I am trying to write an image to canvas using Picture recorder...
drawImage requires dart:ui image
I have successfully imported asset image but getting following error for network image:
[VERBOSE-2:codec.cc(97)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
[VERBOSE-2:shell.cc(186)] Dart Error: Unhandled exception: Exception: operation failed 0 _rootHandleUncaughtError. (dart:async/zone.dart:1112:29) 1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) 2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
code tried so far..
netImage.obtainKey(new ImageConfiguration()).then((val) {
var load = netImage.load(val);
load.addListener((listener, err) async {
ImageInfo imageInfo;
setState(() => imageInfo = listener);
imageInfo.image.toByteData().then((ss) {
Uint8List lst = new Uint8List.view(ss.buffer);
ui.instantiateImageCodec(lst).then((val) {
val.getNextFrame().then((vaal) {
imagetoDraw = vaal.image;
});
});
});
});
});
I faced the same problem. I resolved it by the snippet code as below:
Future<ui.Image> getImage(String path) async {
var completer = Completer<ImageInfo>();
var img = new NetworkImage(path);
img.resolve(const ImageConfiguration()).addListener(ImageStreamListener((info, _) {
completer.complete(info);
}));
ImageInfo imageInfo = await completer.future;
return imageInfo.image;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With