Closed gomander closed 2 months ago
I have the same issue, I suspect the issue lies in the asynchronous retrieval of values in drawImage
during this modification https://github.com/Brooooooklyn/canvas/pull/872.
the following are the verification steps
image.onload = () => {
+ setTimeout(() => {
console.log("Image loaded", image.width, image.height, image.src); // src is correct now
const initialBuffer = canvas.toBuffer("image/png");
@@ -27,4 +28,5 @@ image.onload = () => {
console.log("Final buffer size:", buffer.byteLength); // 114bytes
+ }, 0);
};
or you can do this
await new Promise(r => image.onload = r);
// do something
I have the same issue, I suspect the issue lies in the asynchronous retrieval of values in
drawImage
during this modification #872.the following are the verification steps
image.onload = () => { + setTimeout(() => { console.log("Image loaded", image.width, image.height, image.src); // src is correct now const initialBuffer = canvas.toBuffer("image/png"); @@ -27,4 +28,5 @@ image.onload = () => { console.log("Final buffer size:", buffer.byteLength); // 114bytes + }, 0); };
or you can do this
await new Promise(r => image.onload = r); // do something
https://github.com/Brooooooklyn/canvas/blob/8ca3a9e55d583aa437996a18e3432ceabd477967/src/image.rs#L431-L437 the onloafd before the bitmap Assignment Operation
I have the same issue, I suspect the issue lies in the asynchronous retrieval of values in
drawImage
during this modification #872.the following are the verification steps
image.onload = () => { + setTimeout(() => { console.log("Image loaded", image.width, image.height, image.src); // src is correct now const initialBuffer = canvas.toBuffer("image/png"); @@ -27,4 +28,5 @@ image.onload = () => { console.log("Final buffer size:", buffer.byteLength); // 114bytes + }, 0); };
or you can do this
await new Promise(r => image.onload = r); // do something
Just got to test this out for myself, works great! The latter solution is especially neat. Thanks for the tip!
does this work with const image = await loadImage(src)
?
does this work with
const image = await loadImage(src)
?
It does! This simplifies things a fair bit, so thank you.
Hi, it's me again (sorry). After upgrading to 0.1.55, I'm still getting the same blank result from my test image code as 0.1.54, though for different reasons. It seems that the
.drawImage()
method on SKRSContext2D works fine when provided aCanvas
, but doesn't work when passed anImage
.Again, it's possible that I'm doing something wrong, but here's the result of my testing: