decodeBitmap function
Decodes encoded image bytes (JPEG, PNG, etc.) to an web.ImageBitmap.
Uses createImageBitmap, which decodes off the main thread and avoids the
HTMLImageElement load-event roundtrip. Returns null if decoding fails.
Implementation
Future<web.ImageBitmap?> decodeBitmap(Uint8List bytes) async {
final web.Blob blob = web.Blob([bytes.toJS].toJS);
try {
return await web.window.createImageBitmap(blob).toDart;
} catch (_) {
return null;
}
}