Thank you guys, I tried like you suggested but the bloom seems to not be reapplied correctly, so I simply called the method “createNewRenderTexture” from the tutorial, then launched a timeout and call the screenshot method and it works like a charm.
I have three more questions.
1- If you scale the window to a mobile resolution the screenshot seems to be too zoomed. You can try it here Capturing screenshot on mobile seems zoomed - PLAYCANVAS
2- There is any way to add to the screenshot also any UI visible in scene?
3- I’m trying to make a sharing process with the screenshot. Right now I’m using a code like this:
this part is from the method “takeScreenshot”:
// first, create a new ImageData to contain our pixels
var imgData = this.context.createImageData(colorBuffer.width, colorBuffer.height); // width x height
var data = imgData.data;
// Get a pointer to the current location in the image.
var palette = this.context.getImageData(0, 0, colorBuffer.width, colorBuffer.height); //x,y,w,h
// Wrap your array as a Uint8ClampedArray
palette.data.set(new Uint8ClampedArray(pixels)); // assuming values 0..255, RGBA, pre-mult.
// Repost the data.
this.context.putImageData(palette, 0, 0);
this.context.drawImage(this.canvas, 0, 0);
var image = this.canvas.toDataURL('image/png');
var b64 = this.canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
this.shareFile(image);
and this is the method that I’ve created to share the image:
ShareManager.prototype.shareFile = function (image) {
var filesArr = [];
var file = new File([image], "image.png", {
type: 'image/png',
});
filesArr.push(file);
if (navigator.canShare && navigator.canShare({files: filesArr})) {
navigator.share({
files: filesArr,
title: 'Pictures',
text: 'Our Pictures.',
})
.then(() => console.log('Share was successful.'))
.catch((error) => console.log('Sharing failed', error));
} else {
console.log(`Your system doesn't support sharing files.`);
}
};
I don’t receive any error but It seems to share only the text “Our Pictures”.