Convert Image to Uint8List in Flutter without using Dart:ui

162 views Asked by At

I need to convert Image to Uint8List in Flutter without using Dart:ui because this lib crashes while app is in the background,

this code works for dart:ui and I don't want that because my app crashes on image.toByteData(), explained why on flutter github

var img = await loadImageFromUrl(event.imgUrl);
final recorder = ui.PictureRecorder();
final picCanvas = Canvas(recorder);
var painter = BoxPainter(img, boxes);
painter.paint(picCanvas, size);
picture = recorder.endRecording(); 
final image = picture.toImageSync(size.width.toInt(), size.height.toInt());
final data = await image.toByteData();
final result = data.buffer.asUint8List();

I need a different approach, maybe with image library?

0

There are 0 answers