I was trying to put an asset image into a PDF document.
late Uint8List bmp;
if(i.contains('webp')) bmp = (await img.decodeWebP(bytes))?.buffer.asUint8List() ?? bytes;
else if(i.contains('jpg')) bmp = (await img.decodeJpg(bytes))?.buffer.asUint8List() ?? bytes;
doc.pages[0].graphics.drawImage(PdfBitmap(bmp), Rect.fromLTWH(0, 0, 0, 0));
Before I caught an error
Unsupported operation: Invalid/Unsupported image stream
...
PdfBitmap._initialize (package:syncfusion_flutter_pdf/src/pdf/implementation/graphics/images/pdf_bitmap.dart:193:7)
My question is, yes! obviously how to solve it.
The real culprit is this image plugin. I have to use decodeWebP
to decode a jpeg
, but it doesn't work for a webp
. Weird.
Uint8List? bmp = (await img.decodeWebP(bytes))?.buffer.asUint8List();