ImageCommand API for async image processing #431
brendan-duncan
started this conversation in
General
Replies: 1 comment
-
Hi, that would be easier for developpers to get this info on readme. |
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
-
Part of the major 4.0 update, I am addressing the much asked for async functionality. Image loading and processing is a heavy process, particularly in a language like Dart that lacks things like shared memory or SIMD instructions.
Coming up with a way to do image processing async, in a way that works with Dart's Isolate memory model, was tricky. I came up with an ImageCommand API I think will work.
A sequence of image loading / processing / saving functions can be defined in an ImageCommand. To load a jpeg image, resize it, and save it to a png file, you could do the following:
Nothing has actually been run yet, this just recorded the commands into cmd. You can execute the commands asynchronously with
Or you can execute the commands synchronously with
cmd.execute();
You can access the resulting image from the execution results with
This will be the resized Image.
If the commands had encoded an Image to a format, which happened with the encodePngFile command, you can access the encoded bytes with:
getImage and getBytes will execute the commands if they haven't been executed yet. As such, there are also getImageAsync and getBytesAsync variants of the functions.
Beta Was this translation helpful? Give feedback.
All reactions