0

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 !

user2505650
  • 1,293
  • 6
  • 20
  • 38
  • In what way do you want to transform the image into a byte array? For example, do you want it in an image format (e.g. JPEG) or do you want the raw color information from the image pixels? – Guffa Nov 17 '13 at 18:20

1 Answers1

0

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);
anderZubi
  • 6,414
  • 5
  • 37
  • 67
  • I tried it but i have ArgumentException in wBitmap.SaveJpeg(mStream, TheImage.DecodePixelWidth, TheImage.DecodePixelHeight, 0, 100); – user2505650 Nov 17 '13 at 18:46