error on load image using rootBundle in flutter

600 views
Skip to first unread message

Niyazi Toros

unread,
Jul 31, 2018, 4:25:49 AM7/31/18
to Flutter Dev
Hi,

I am trying to load image using rootBundle in flutter and I get this below error.
Any help please.

E/flutter (24839): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:

E/flutter (24839): Unable to load asset: packages/myAppName/assets/images/ReceiptRaw_1.jpg



Future<bool> makeReceiptImage() async {

 
// load the receipt jpeg

 
String mImagePath = await rootBundle.loadString('packages/myAppName/assets/images/ReceiptRaw_1.jpg');

 
print("mImagePath: $mImagePath");

 
Image _receiptImage = await decodeImage(new File(mImagePath).readAsBytesSync());

  drawString
(_receiptImage, arial_48, 440, 30, Customer Name”, color: 0xFF000000);


 

 
// Write it to disk as a different jpeg

 
var new_jpeg = await encodeJpg(_receiptImage);

 
String newImagePath = await rootBundle.loadString('packages/myAppName/assets/images/ReceiptRaw_2.jpg');

  await
new File(‘$newImagePath’).writeAsBytesSync(new_jpeg);

}





The Dart Console App is working with similar code


import 'dart:io';

import 'dart:convert';

import 'dart:async';

import 'package:image/image.dart';


void main() async {


 
// load the receipt jpeg

 
String mImagePath = 'images/ReceiptRaw_1.jpg';

 
Image _receiptImage = decodeImage(new File(mImagePath).readAsBytesSync());

  drawString
(_receiptImage, arial_48, 440, 30, Customer Name”, color: 0xFF000000);



 
// Write it to disk as a different jpeg

 
var new_jpeg = encodeJpg(_receiptImage);

 
new File('images/ReceiptRaw_1.jpg').writeAsBytesSync(new_jpeg);

}

 




Reply all
Reply to author
Forward
0 new messages