Hello, I’m trying to copy the canvas to collect data. It’s fairly straight forward code.
captureCanvas() {
var img = new Image;
img.onload = () => {
var mc = document.getElementById('machine-canvas');
var context = mc.getContext('2d');
var scale = this.scaleImage(img.width, img.height, 224, 224, false); //math
context.drawImage(
img,
scale.targetleft,
scale.targettop,
scale.width,
scale.height
);
}
var holder = document.querySelector('canvas').toDataURL();
img.src = holder;
}
Sometimes the canvas is black though, other times it works as expected. It seems to only work when the secondary canvas is visible and Phaser one is hidden. Does anyone know how to solve the black screen with canvas copy?