3

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

Image

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

My Car
  • 4,198
  • 5
  • 17
  • 50
Pabdev
  • 406
  • 3
  • 14
  • 2
    Can you share the image so that we can test it out? – MendelG Dec 19 '22 at 01:04
  • @MendelG Sorry unfortunately the image I can not share as per the policy of my company as its confidential. The Images are in JPG format with 30000x30000 pixels and around 515MB size (basically AOI device images). – Pabdev Dec 19 '22 at 04:09

1 Answers1

2

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

Sajjad
  • 2,593
  • 16
  • 26
  • using cacheHeight and cacheWidth worked perfectly. Now the image is loading. Thank you so much. It is due to the high resolution image which is bigger in size, so was taking more memory it seems. – Pabdev Dec 20 '22 at 11:05