How to take screenshot?

How to take screenshot?
0.0 0


I was trying to take screenshot of game over screen and share it across.

What is the best quick way for Android/iOS from cocos2d-x javascript code ?


You can take a screen shot in this way:

screenshot: function (fileName) {
    var tex = new cc.RenderTexture(winSize.width, winSize.height, cc.Texture2D.PIXEL_FORMAT_RGBA8888);
    tex.setPosition(cc.p(winSize.width / 2, winSize.height / 2));

    var imgPath = jsb.fileUtils.getWritablePath();
    if (imgPath.length == 0) {
    var result = tex.saveToFile(fileName, cc.IMAGE_FORMAT_JPEG);
    if (result) {
        imgPath += fileName;
        cc.log("save image:" + imgPath);
        return imgPath;
    return "";



Am working on screenshot. I have used above code. Am able to succeed in IOS platform. But in android am getting black image. Am using version 3.5.

By using imagePath i have created sprite. In Ios am bale to create Sprite. But in Android am getting following error.

Get data from file(/data/data/org.cocos2dx.MyPuppy/files/savedImageName) failed! 

I need help. Is anyone getting same error?

Thanks & Regards



Is anyone solved the above issue?


add little delay …and it should work fine


Any way to get Base64 data from texture in web?