encodeThumbnailPng method

Future<bool> encodeThumbnailPng()

Reads thumbnail back as PNG into thumbnailPng. False when there is no thumbnail or the readback failed (a format the display path cannot present).

Implementation

Future<bool> encodeThumbnailPng() async {
  if (thumbnailPng != null) return true;
  final texture = thumbnail;
  if (texture == null) return false;
  try {
    final image = texture.asImage();
    final data = await image.toByteData(format: ui.ImageByteFormat.png);
    image.dispose();
    if (data == null) return false;
    thumbnailPng = data.buffer.asUint8List(
      data.offsetInBytes,
      data.lengthInBytes,
    );
    return true;
  } catch (_) {
    return false;
  }
}