Skip to content

Commit

Permalink
🐛 Fix image ArrayBuffer recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jun 12, 2024
1 parent 2ddd6e0 commit 76df6f1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ export let View = (function () {
}

imgType = imgType || "image/png";
withLogo = withLogo || true;

const canvas = this.wasm.canvas();

Expand Down Expand Up @@ -493,7 +492,18 @@ export let View = (function () {
*/
View.prototype.getCanvasBuffer = async function (imgType, width, height, withLogo=true) {
const c = await this.getCanvasContext(imgType, width, height, withLogo);
return c.getContext('2d').getImageData(0, 0, c.width, c.height).data.buffer;
return new Promise((resolve, reject) => {
c.toBlob(blob => {
if (blob) {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = () => reject(new Error('Error reading blob as ArrayBuffer'));
reader.readAsArrayBuffer(blob);
} else {
reject(new Error('Canvas toBlob failed'));
}
}, imgType);
});
}

View.prototype.selectLayer = function (layer) {
Expand Down

0 comments on commit 76df6f1

Please sign in to comment.