Flutter - save ImageProvider to file

Viewed 433

I need to resize image file and save it back to cache. To resize image:

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

I guess img object contains resized image data. How to save it to file to access it when required?

1 Answers

As I see, you already resize your image. you can try this code to paste your new image. but be carefull for img, because it have to buffer like 5D FF A0

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

final File newImagePath = File("/example/path"); //pasting path

newImagePath.writeAsBytesSync(img);
Related