Replies: 2 comments
-
The let img = new Image()
img.src = fs.readFileSync('./spritesheet.png')
console.log('loaded?', img.complete)
// loaded? true You can also construct a const loadImageSync = path => Object.assign(new Image(), {src:fs.readFileSync(path)}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Version 3.0 adds the ability to pass Buffer objects to the Image constructor, so you can now synchronously load images that way too: import {readFileSync} from 'fs
import {Image} from 'skia-canvas'
let img = new Image(readFileSync("./spritesheet.png"))
console.log('loaded?', img.complete)
// loaded? true |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question: Is there a way to synchronously load an image?
My usecase/reason is for loading spritesheet images on startup (and concurrency/non-blocking isnt important, because my app must have this loaded to do anything), and having it synchronous will reduce the async keyword spreading in my code and allow a nicer/cleaner setup.
Simplified code example, just to show some code:
Side note: I don't want to use top-level await for reasons, and purely out of curiousity, is there a technical reason why
Image
is async if a Buffer is passed, what necessitates async in that scenario?Thank you.
Beta Was this translation helpful? Give feedback.
All reactions