Search code examples
c#imagestreamresizeimage-resizing

how to get path of new from steam?


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


Solution

  • 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.