2

I'm new for cocos2d-x and I'm using v3.1. I wrote an app using cocos2d before and now I want to add an android version by cocos2d-x.

After checking online, I use this code for saving my screen image:

void Game1::takePhoto(Ref *pSender){

Size size = Director::getInstance()->getWinSize();
RenderTexture* texture = RenderTexture::create((int)size.width, (int)size.height);
texture->setPosition(Point(size.width, size.height));
texture->begin();
Director::getInstance()->getRunningScene()->visit();
texture->end();
if (texture->saveToFile("screenshot.png", kCCImageFormatPNG)){
    CCLOG("screen captured");
}

}

Where did the file be saved? I can't find it on my album, how can I save it to album for android device?

1 Answers1

0

it saved to where getWriteablePath() returns.

GameDeveloper
  • 1,029
  • 1
  • 7
  • 12
  • But how can I save it to Android device's gallery ( album)? Is it possible to do this by C++ using cocos2d-x? – hkcitydancer Jun 09 '14 at 07:41
  • You are on the right track. http://www.cocos2d-x.org/wiki/How_to_Save_a_Screenshot – GameDeveloper Jun 09 '14 at 14:27
  • I get a log showing my image is safe as " /data/data/com.xxx.xxx/files/screenshot.png" But how can I save it to gallery? Should I call java code for this action? or I can use C++ to do it? I searched for cocos2dx forum and stack overflow..... seems nobody can answer this question.... Can you help? Thanks – hkcitydancer Jun 10 '14 at 06:40
  • I don't currently develop for Android, but I think you need to call: `MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);` – GameDeveloper Jun 10 '14 at 16:27
  • i tried `cpp: auto fullPath = FileUtils::getInstance()->getWritablePath() + fileName;` JAVA: `Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(filePath); Uri contentUri = Uri.fromFile(f); mediaScanIntent.setData(contentUri); me.sendBroadcast(mediaScanIntent);` But I still can't see the image on my gallery, any hints? – hkcitydancer Jun 12 '14 at 11:08