Set the width and height on the canvas used to convert imageData to data URL

This commit is contained in:
DD Liu 2020-05-24 22:35:59 -04:00
parent 87e01639c0
commit 5a35dd8614

View file

@ -43,6 +43,7 @@ class Playground extends React.Component {
image: svgString, // svg string or data URI
rtl: rtl
};
this.reusableCanvas = document.createElement('canvas');
}
handleUpdateName (name) {
this.setState({name});
@ -55,11 +56,12 @@ class Playground extends React.Component {
} else { // is Bitmap
// image parameter has type ImageData
// paint editor takes dataURI as input
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
this.reusableCanvas.width = image.width;
this.reusableCanvas.height = image.height;
const context = this.reusableCanvas.getContext('2d');
context.putImageData(image, 0, 0);
this.setState({
image: canvas.toDataURL('image/png'),
image: this.reusableCanvas.toDataURL('image/png'),
rotationCenterX: rotationCenterX,
rotationCenterY: rotationCenterY
});