我正在开发一个图像查看器桌面应用程序使用Flutter 翼.我试图使用Ffltter 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

当我在任何其他内置图像查看器的窗口中打开相同的图像时,它会打开.在Flutter 中,如果使用相同的代码Image.file(‘mall Size.jpg’),它工作得很好.

@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

      ),
    );
  }

我也try 了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,
         ),
      ),
    );
  }

以下是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在创建时为提供者调用初始化函数

如何让GridView.builder用另外两个小部件来占据屏幕的剩余部分

如何刷新future 的构建器时,没有OBS变量的内部在Ffltter?

错误:找不到字体功能类型.Ffltter Google_Fonts包错误

Flutter 中的面向对象模式

如何知道当前屏幕是否处于抖动状态?

GitHub Actions工作流secret中的特殊字符未被保留

如何将请求字段正确添加到DART多部分请求

在 Flutter 中滑动关闭 PageView.builder 时出现问题

Flutter:我的应用程序是否需要包含退款购买?

Flutter中如何实现带有变化图标的浮动操作按钮?

为什么我们需要使用ChangeNotifierProvider而不是仅仅使用ChangeNotifier?

围绕父组件旋转位置组件

有没有办法在没有收缩包装的情况下在列中使用 ListView.Builder?

Flutter可滚动定位列表支持rtl方向吗?

Flutterfire Configure - 未处理的异常和没有 firebase 初始化

有没有办法为文本中的下划线创建自定义样式?

使用 onPressed 切换到另一个屏幕无法正常工作

如何按键在 map 列表中搜索

TextSpan 避免符号字符串组上的换行符