1

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?

user1209216
  • 7,404
  • 12
  • 60
  • 123

1 Answers1

-1

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);
SefaUn
  • 824
  • 1
  • 7
  • 23
  • `File.writeAsBytesSync` takes `List` as a parameter, not `ImageProvider` – pskink Sep 14 '21 at 11:12
  • research how can you convert `ImageProvider` to `List` – SefaUn Sep 14 '21 at 13:12
  • could you check this issue: https://stackoverflow.com/questions/49701654/how-can-i-read-from-disk-and-resize-an-image-in-flutter-dart – SefaUn Sep 14 '21 at 13:21
  • I've seen that, but it does not meet my needs. I want to load reduced version, and avoid loading original image to save memory. If possible, without using any platform specific code by myself – user1209216 Sep 14 '21 at 17:55