fromEncodedBuffer static method

ImageRef fromEncodedBuffer(
  1. Uint8List bytes, {
  2. BufferImageLoadOptions? options,
})

Creates ImageRef from encoded buffer, e.g. from jpeg.

Implementation

static ImageRef fromEncodedBuffer(Uint8List bytes,
    {BufferImageLoadOptions? options}) {
  return using((Arena arena) {
    BufferImageLoadOptions resolvedOptions =
        options ?? BufferImageLoadOptions();

    Pointer<Uint8> pBytes = arena.allocate<Uint8>(bytes.length);
    pBytes.asTypedList(bytes.length).setAll(0, bytes);

    Pointer<CBufferImageLoadOptions> pConfig =
        arena<CBufferImageLoadOptions>();
    pConfig.ref.cropRect.x = resolvedOptions.cropRect.left;
    pConfig.ref.cropRect.y = resolvedOptions.cropRect.top;
    pConfig.ref.cropRect.width = resolvedOptions.cropRect.width;
    pConfig.ref.cropRect.height = resolvedOptions.cropRect.height;

    pConfig.ref.colorConversion = resolvedOptions.colorConversion.index;

    pConfig.ref.canvasColor = resolvedOptions.canvasColor.index;

    pConfig.ref.loadMode = resolvedOptions.loadMode.index;

    String uuid = _consumeString(
        _nativeCreateFromEncodedBuffer(pBytes, bytes.length, pConfig));

    ImageRef ref = ImageRef._(uuid);
    return ref;
  });
}