0

I have a image icon.png and i am using FFImageloading plugin to re-size image. Than I am converting Stream to ImageSource and displaying the result. works fine

How to save re-size image stream into cache folder and get path of it? can someone point me in right direction plz

var stream = await ImageService.Instance.LoadFile("icon.png")
         .DownSample(width: 200)
         .AsPNGStreamAsync();

ImageSource myImageS= ImageSource.FromStream(() => stream);
DisplayImage.Source = myImageS;

I can use File.Move but i would need path of stream content

1 Answers1

0

You would need to save it back to the disk. The current code does not save it yet. You can save it using something like:

// Save the file 
using (var fileStream = new FileStream("icon2.png", FileMode.Create))
{
    BitmapEncoder encoder = new PngBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(myImageS));
    encoder.Save(fileStream);
}

Note: I used this answer for help with this.

SunsetQuest
  • 8,041
  • 2
  • 47
  • 42
  • i see, thanks for letting me know my code wasn't saving them image. I am just a lil confoused on how to save a image. for ex: what is icon2.png? is this random name of new image? –  May 31 '21 at 19:30
  • 1
    Correct, icon2.png was just some random name I picked. You could use anything here you like, even the original filename if you like. You can just add this code under your existing code. – SunsetQuest May 31 '21 at 19:32
  • Hopefully it saves in the same path. If not you might need to capture the path then add the path to that location. – SunsetQuest May 31 '21 at 19:38
  • 1
    it makes sense, it is working fine now. thanks –  May 31 '21 at 19:46