loadImageFromAsset function
load an image from asset
Implementation
Future<Image> loadImageFromAsset(String fileName, {bool isAsset = true, bool makeGray = false}) {
final c = Completer<Image>();
Future<Uint8List> dataFuture;
if (isAsset){
dataFuture = rootBundle.load(fileName).then((data) => data.buffer.asUint8List());
}
else{
dataFuture = File(fileName).readAsBytes();
}
dataFuture.then((data) {
// if(makeGray){
// img.Image image = img.grayscale(img.decodeJpg(data));
// data = img.encodeJpg(image);
// }
instantiateImageCodec(data).then((codec) {
codec.getNextFrame().then((frameInfo) {
c.complete(frameInfo.image);
});
});
}).catchError((error) {
c.completeError(error);
});
return c.future;
}