如何在Flutter中从URL裁剪和下载图像?

时间:2019-09-12 16:53:15

标签: flutter

我尝试使用image_cropimage_cropper之类的各种库。但是它们只允许您裁剪本地图像,而我想裁剪在线图像并存储裁剪后的图像。最好的方法是什么?

1 个答案:

答案 0 :(得分:0)

使用Flutter cached_network_imageflutter_cache_manager(缓存的网络映像使用flutter_cache_manager存储和检索文件),您可以从网络获取文件。

var imageFile =
        await DefaultCacheManager().getSingleFile('https://your_network_image_url');

然后,您可以将此文件发送到image_cropper进行裁剪。

Future<Null> _cropImage(File imageFile) async {
    File croppedFile = await ImageCropper.cropImage(
      sourcePath: imageFile.path,
      ratioX: 1.0,
      ratioY: 1.0,
      maxWidth: 512,
      maxHeight: 512,
    );
}