Hi,
I am trying to fetch an image from facebook and passing the raw image data to cocos2d to create a sprite. My function to fetch the image from the URL is as follows:
@
String urlString = “http://graph.facebook.com/”+user.getId()+“/picture?type=large”;
Log.i(“facebook”, “url is” + urlString);
Bitmap pic = null;
pic = BitmapFactory
.decodeStream((InputStream) new URL(
urlString)
.getContent());
int[] pixels = new int[pic.getWidth() * pic.getHeight()];
pic.getPixels(pixels, 0, pic.getWidth(), 0, 0,pic.getWidth(),pic.getHeight());
int len = pic.getWidth()
* pic.getHeight();
// Log.i(“colordata”,“length is”+len);
nativeFbUserName(pixels,len,pic.getWidth(), pic.getHeight());@
In the cocos2d side im using the following JNI call, which in turn schedules a function to create a sprite since we cant access the opengl context in this thread (Any better way to do this?)
@
void Java_com_WBS_Test0001_Test0001_nativeFbUserName(JNIEnv env, jobject thiz,
jintArray name, jint len, jint width, jint height) {
CCLog;
jintjArr = env->GetIntArrayElements(name,NULL);
int username[len];
for (int i=0; i<len; i++){
username[i] = (int)jArr[i];
}
HelloWorld::getShared()->picLen = (int)len;
HelloWorld::getShared()>picHeight = height;>picWidth = width;
HelloWorld::getShared
HelloWorld::getShared~~>saveArray;
HelloWorld::getShared~~>schedule,0.1);
}
void HelloWorld::addSprite
{
CCLog;
this~~>unschedule);
CCImage *ccimg = new CCImage;
ccimg~~>initWithImageData 3, picWidth, picHeight, 32);
CCTexture2D tex = new CCTexture2D;
bool val = tex~~>initWithImage;
// bool val = tex~~>initWithData0,picWidth,picHeight, CCSizeMake);
CCLog;
CCSpritespriteToAdd = CCSprite::createWithTexture;
spriteToAdd~~>setPosition);
this~~>addChild(spriteToAdd);
}
void HelloWorld::saveArray(int *arrayToSave)
{
arr = new int[picLen];
for(int i = 0; i < picLen; i++){
arr[i] = arrayToSave[i];
//CCLog(“d d”,i,arr[i]);
}
}
@
This creates the sprite alright, but it has a blue tinge to it. How do i get rid of this tinge?
I tried this with another image of the net also. I used this image http://www.mathewingram.com/work/wp-content/themes/thesis/rotator/335f69c5de_small.jpg (random image) and the result is attached in the screenshot
Thanks.
Screen Shot 2013-02-07 at 6.47.02 PM.png (382.8 KB)