2

I display images in my WPF app using BitmapImage. However, I would like an easy way to save these (as JPG) to a different location (ideally into a Stream or object that can be passed around).

Is it possible using BitmapImage or do I have to use other means? If so what other means are there for either loading an Image and saving as JPG or converting a BitmapImage into this element to then save off?

Thanks

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Chris
  • 26,744
  • 48
  • 193
  • 345

1 Answers1

2

Something like:

public byte[] GetJPGFromImageControl(BitmapImage imageC)
{
    MemoryStream memStream = new MemoryStream();
    JpegBitmapEncoder encoder = new JpegBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(imageC));
    encoder.Save(memStream);
    return memStream.GetBuffer();
}

(from: WPF Image to byte[])

Community
  • 1
  • 1
Iain
  • 2,500
  • 1
  • 20
  • 24