'How to solve "Invalid image data" error in Flutter
I'm using SQLite for storing data locally.
insert an image as a string and get them to show here is the error that occurs _Exception (Exception: Invalid image data)
.
Encode image code:
Future pickImage(ImageSource source) async {
final image = await ImagePicker().pickImage(source: source);
if (image == null) return;
final imagePermanent = File(image.path);
setState(() => _image = imagePermanent);
imageData = base64Encode(_image!.readAsBytesSync());
print(imageData);
return imageData;}
Decode image in display page:
showImage(String image) {
return Image.memory(base64Decode (image) );
}
Display in code:
showImage(widget.euser.image.toString()),
Error Shows :
Exception has occurred._Exception (Exception: **Invalid image data**)
Console logs show like this:
E/FlutterJNI(30407): Failed to decode image
E/FlutterJNI(30407): android.graphics.ImageDecoder$DecodeException:
Failed to create image decoder with message 'unimplemented'Input contained an error.
E/FlutterJNI(30407):
at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI(30407):
at android.graphics.ImageDecoder.access$200(ImageDecoder.java:173)
E/FlutterJNI(30407):
at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:250)
E/FlutterJNI(30407):
at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1862)
E/FlutterJNI(30407):
at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1855)
E/FlutterJNI(30407):
at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:514)
Error image:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|