I am developing an image viewer desktop app using flutter. The images which I am trying to open using flutter Image.file('largeImage.jpg') but it fails to load the image with following error:
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞═════════════════════════════════════
The following _Exception was thrown resolving an image frame:
Exception: Codec failed to produce an image, possibly due to invalid image data.
When the exception was thrown, this was the stack
Path: images/largeImage.jpg
The same image when I open in any other windows built in image viewer then it opens up. In flutter if with same code Image.file('smallSize.jpg') it works fine.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text('Image Viewer'),
),
body: Center(
child:
//not working
Image.file(File('images/largeImage.JPG')),//515MB
//working
Image.file(File('images/smallImage.JPG')), //10MB
),
);
}
I also tried with extended_image library but it doesn't display anything (just a blank window) and no exceptions.
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text('Image Viewer'),
),
body: Center(
child:
ExtendedImage.file(
width: 600,
height: 400,
File('images/Panel.JPG'),
//cancelToken: cancellationToken,
),
),
);
}
Below is the flutter.doctor summary:
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.3.9, on Microsoft Windows [Version
10.0.19041.1415], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.2) [√] Android Studio (version 2020.3) [√] VS Code (version 1.74.0) [√] Connected device (3 available) [√] HTTP Host Availability
• No issues found!
Thank you in advance
could you please test below code, to be honest I am not sure about this.
Image.file(File(path),
width: 200,
height: 200,
cacheHeight: 200,
cacheWidth: 200,
)
and read this useful comment