flutter - 无法在 flutter 图像小部件中打开大尺寸(500MB)图像

标签 flutter image dart codec flutter-desktop

我正在使用 Flutter 开发图像查看器桌面应用程序。我尝试使用 flutter Image.file('largeImage.jpg') 打开的图像,但它无法加载图像并出现以下错误:

 ══╡ 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

当我在图像查看器内置的任何其他窗口中打开相同的图像时,它会打开。如果使用相同的代码 Image.file('smallSize.jpg') 在 flutter 中它工作正常。

@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

      ),
    );
  }

我也试过 extended_image库,但它不显示任何内容(只是一个空白窗口)并且没有异常。

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,
         ),
      ),
    );
  }

下面是 flutter.doctor 的总结:

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!

提前致谢

最佳答案

请你测试下面的代码,老实说,我对此不确定。

Image.file(File(path),
            width: 200,
            height: 200,
            cacheHeight: 200,
            cacheWidth: 200,
          )

并阅读这个有用的 comment

关于flutter - 无法在 flutter 图像小部件中打开大尺寸(500MB)图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74822520/

相关文章:

ios - 错误 : could not find included file 'Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths (in target 'Runner' )

flutter - 为什么我的扩展容器不占用设备的剩余高度?

android - Flutter:圆形颜色选择器(包:flutter_colorpicker)

dart - flutter 导航流程中的第二页不是全尺寸

php - 如何在php中将文件从一个页面发送到另一个页面

html - 加载大量图像的最佳方式

html - 将一个 div 减半并达到 100% 高

android - flutter Android资源链接失败@mipmap/ic_launcher未找到

Android Studio 未连接设备问题

dart - Flutter 在执行后台任务时显示 Progress HUD