Files
MrbWebLibre/app/lib/features/geckoview/utils/image_helper.dart
T
2024-09-13 09:11:06 +02:00

30 lines
550 B
Dart

import 'dart:typed_data';
import 'dart:ui';
Future<Image?> tryDecodeImage(
Uint8List bytes, {
int? targetWidth,
int? targetHeight,
bool allowUpscaling = true,
}) async {
try {
final codec = await instantiateImageCodec(
bytes,
targetWidth: targetWidth,
targetHeight: targetHeight,
allowUpscaling: allowUpscaling,
);
final frameInfo = await codec.getNextFrame();
final image = frameInfo.image;
if (image.width > 0) {
return image;
}
} catch (e) {
//swallow
}
return null;
}