proposed and upcoming APIs and how they may be able to be used with CanvasKit. Change-Id: I085e65e7e3c58ef2cbe2ce60ddd813b2c531c890 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296752 Reviewed-by: Kevin Lubick <kjlubick@google.com>
2.6 KiB
ImageDecoder API
Date Updated: June 16, 2020
Summary and Links
The ImageDecoder API
handles decoding of both still and animated images.
Similar to the larger web codecs
proposal which is focused more on video and audio.
The ImageDecoder API could be used with CanvasKit.MakeImageFromCanvasImageSource
for creating CanvasKit compatible SkImage
s.
For still images, the createImageBitmap(blob)
API achieves the same result.
Currently available as a prototype behind the --enable-blink-features=WebCodecs
flag
in Chrome Canary, works in version 85.0.4175.0.
Running the prototype
- Download and install Chrome Canary. Verify that you have version 85.0.4175.0 or later.
- Close ALL open instances of chromium browsers, including chrome.
- Run Chrome Canary with the
--enable-blink-features=WebCodecs
flag.
MacOS: Run /applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --enable-blink-features=WebCodecs
Windows, Linux: https://www.chromium.org/developers/how-tos/run-chromium-with-flags
- Navigate to: http://storage.googleapis.com/dalecurtis/test-gif.html?src=giphy.gif
- You should see a cute animated cat illustration.
Example API Usage with CanvasKit
With a still image:
const response = await fetch(stillImageUrl); // e.g. png or jpeg
const data = await response.arrayBuffer();
const imageDecoder = new ImageDecoder({ data });
const imageBitmap = await imageDecoder.decode();
const skImage = CanvasKit.MakeImageFromCanvasImageSource(imageBitmap);
// do something with skImage, such as drawing it
With an animated image:
const response = await fetch(animatedImageUrl); // e.g. gif or mjpeg
const data = await response.arrayBuffer();
const imageDecoder = new ImageDecoder({ data });
for (let frame = 0; frame < imageDecoder.frameCount; frame++) {
const imageBitmap = await imageDecoder.decode(frame);
const skImage = CanvasKit.MakeImageFromCanvasImageSource(imageBitmap);
// do something with skImage, such as drawing it
}