I am looking for a method to transform a BitmapImage into a byte[] in c# .
Let's say that I have those two variables :
byte[] ByteArray;
BitmapImage TheImage;
How can I make
ByteArray = TheImage
Thank you very much for your help !
I am looking for a method to transform a BitmapImage into a byte[] in c# .
Let's say that I have those two variables :
byte[] ByteArray;
BitmapImage TheImage;
How can I make
ByteArray = TheImage
Thank you very much for your help !
You can use the SaveJpeg
method of WriteableBitmap
:
WriteableBitmap wBitmap = new WriteableBitmap(TheImage);
MemoryStream mStream = new MemoryStream();
wBitmap.SaveJpeg(mStream, TheImage.DecodePixelWidth, TheImage.DecodePixelHeight, 0, 100);
mStream.Read(ByteArray, 0, (int)mStream.Length);