[cocos2dx android]Rendering CCSprite using raw data from Bitmap -
i trying fetch image url bitmap , using raw info bitmap trying create ccsprite. issue here image corrupted when display sprite. created standalone android application(no cocos2dx) , used same code fetch , display bitmap , displayed correctly. reason why image not beingness rendered in cocos2dx?
my code fetch image url is:
string urlstring = "http://www.mathewingram.com/work/wp-content/themes/thesis/rotator/335f69c5de_small.jpg";//http://graph.facebook.com/"+user.getid()+"/picture?type=large"; 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(); nativefbusername(pixels,len,pic.getwidth(), pic.getheight());
the function "nativefbusername" phone call native c++ function :
void java_com_wbs_test0001_test0001_nativefbusername(jnienv *env, jobject thiz,jintarray name, jint len, jint width, jint height) { jint *jarr = env->getintarrayelements(name,null); int username[len]; (int i=0; i<len; i++){ username[i] = (int)jarr[i]; } helloworld::getshared()->piclen = (int)len; helloworld::getshared()->picheight = (int)height; helloworld::getshared()->picwidth = (int)width; helloworld::getshared()->savearray(username); helloworld::getshared()->schedule(sel_schedule(&helloworld::addsprite),0.1); } void helloworld::savearray(int *arraytosave) { arr = new int[piclen]; for(int = 0; < piclen; i++){ arr[i] = arraytosave[i]; } } void helloworld::addsprite(float time) { this->unschedule(sel_schedule(&helloworld::addsprite)); cctexture2d *tex = new cctexture2d(); bool val = tex->initwithdata(arr,(cocos2d::cctexture2dpixelformat)0,picwidth,picheight, ccsizemake(picwidth,picheight)); cclog("flag %d",val); ccsprite *spritetoadd = ccsprite::createwithtexture(tex); spritetoadd->setposition(ccp(500, 300)); this->addchild(spritetoadd); }
edit: found link access raw info in argb_8888 android bitmap states might bug. has found solution this?
edit noticed corruption of images on lower right corner of image.i not sure why happening , how prepare it. ideas?
edit end
answering own question, obtained byte array bitmap using:
byte[] info = null; bytearrayoutputstream baos = new bytearrayoutputstream(); pic.compress(bitmap.compressformat.jpeg, 100, baos); info = baos.tobytearray();
and passed byte array native code.
android bitmap cocos2d-x ccsprite
No comments:
Post a Comment