Screenshot in creator snaps Black shutter screenshot: appears black

i was fine with that in last build in my facebook instant game and my screenshot function was working fine. But suddenly i observed it and it is not work now.

Any Guess?
my camera settings:
zoom ratio 1
depth -1
culling selected all
clear flag all

Code:

   GetScreenshot(cameraRef) {
    let node = new cc.Node();
    node.parent = cc.director.getScene();
    let camera = node.addComponent(cc.Camera);

    // Set the CullingMask of the screenshot you want
    camera.cullingMask = cameraRef.cullingMask;

    node.setParent(cameraRef.node.parent);
    node.position = cameraRef.node.position;

    // Create a new RenderTexture and set this new RenderTexture to the camera's targetTexture so that the camera content will be rendered to this new RenderTexture
    let texture = new cc.RenderTexture();
    let gl = cc.game._renderContext;
    let width = cc.visibleRect.width;
    let height = cc.visibleRect.height;

    // If the Mask component is not included in the screenshot, you don't need to pass the third parameter.
    texture.initWithSize(width, height);
    camera.targetTexture = texture;

    // Render the camera once, updating the content once into RenderTexture
    camera.render();

    // This allows the data to be obtained from the rendertexture.
    let data = texture.readPixels();

    // Then you can manipulate the data.
    let canvas = document.createElement('canvas');
    let ctx = canvas.getContext('2d');
    canvas.width = texture.width;
    canvas.height = texture.height;

    let rowBytes = width * 4;
    for (let row = 0; row < height; row++) {
        let srow = height - 1 - row;
        let imageData = ctx.createImageData(width, 1);
        let start = srow * width * 4;
        for (let i = 0; i < rowBytes; i++) {
            imageData.data[i] = data[start + i];
        }

        ctx.putImageData(imageData, 0, row);
    }

    let dataURL = canvas.toDataURL("image/jpeg");
    // let img = document.createElement("img");
    //img.src = dataURL;



    return dataURL;

}

Any help?

you can refence:


we had update this demo to creator 2.x version,and fixed some bugs about screenshot and share

1 Like

ok thanks. i check the link