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

4uqofj5v  于 2022-12-24  发布在  Flutter
关注(0)|答案(1)|浏览(106)

我正在使用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

当我在图像查看器中打开任何其他内置窗口时,同样的图像会打开。在Flutter中,如果使用相同的代码Image.file('smallSize.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

      ),
    );
  }

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

以下是www.example.com的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!

先谢谢你

fivyi3re

fivyi3re1#

你能不能测试一下下面的代码,老实说我不太确定。

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

并阅读这篇有用的评论

相关问题