【问题标题】:Flutter - save ImageProvider to fileFlutter - 将 ImageProvider 保存到文件
【发布时间】:2021-09-14 10:26:57
【问题描述】:

我需要调整图像文件的大小并将其保存回缓存。调整图片大小:

ImageProvider img = ResizeImage.resizeIfNeeded(1024, null, FileImage(File(path)));

我猜img 对象包含调整大小的图像数据。需要时如何保存到文件中访问?

【问题讨论】:

    标签: image flutter dart image-resizing


    【解决方案1】:

    如我所见,您已经调整了图像大小。您可以尝试使用此代码粘贴新图像。但要小心img,因为它必须像5D FF A0 一样缓冲

    ImageProvider img = ResizeImage.resizeIfNeeded(1024, null, FileImage(File(path)));
    
    final File newImagePath = File("/example/path"); //pasting path
    
    newImagePath.writeAsBytesSync(img);
    

    【讨论】:

    • File.writeAsBytesSync 将List<int> 作为参数,而不是ImageProvider
    • 研究如何将ImageProvider 转换为List<int>
    • 你能检查一下这个问题吗:stackoverflow.com/questions/49701654/…
    • 我已经看到了,但它不能满足我的需求。我想加载缩小版,并避免加载原始图像以节省内存。如果可能,我自己不使用任何特定于平台的代码
    猜你喜欢
    • 2020-03-11
    • 2018-11-23
    • 2021-01-06
    • 2020-09-09
    • 2020-09-23
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    相关资源
    最近更新 更多