I want to take screenshots and save it in the gallery. What I have tried:
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRenderTexture* texture = CCRenderTexture::create((int)size.width, (int)size.height, kCCTexture2DPixelFormat_RGBA8888);
texture->setPosition(ccp(size.width/2, size.height/2));
texture->begin();
CCDirector::sharedDirector()->getRunningScene()->visit();
texture->end();
texture->saveToFile("scrshot.png", kCCImageFormatJPEG);
in iOS it is working perfectly and am able to save image in to documents, but the problem is in android :
There are two possibilities
1) texture->saveToFile("scrshot.png", kCCImageFormatJPEG); or texture->saveToFile("My path"); -> It compiles but where is the image saved?
2) Use JNI to save Bitmap file -> problem is how to cast CCRenderTexture to Bitmap and parse it.
I solve this issue quickly but forgot to give the answer but now giving because it may help someone
My code is only for iOS and android
code is
In My BridgeClass
For iOS it will save to gallery
For android there is a class androidJNI.cpp
And android native method for save image to data/data
when access this image from data/data will not accessible directly here save this image to sd card and the access it from cocos2dx
but for android have to get writable path using getWritablePath function and parse this value to saveToFile function and the
SaveImageAdmobJNI(true);
will call native method ,in native method you can save take the image path and save it to galleryNote: getWritablePath() - this function will give you the path from data->data->YOUR_PAKAGE
Feel free to ask queries.