1

I try to find in google how to convert imageSource to byte[] - and i can't find the why to do it.

Someone can help here ?

Thanks.

Yanshof
  • 9,659
  • 21
  • 95
  • 195
  • 1
    Possible duplicate of [How to convert ImageSource to Byte array?](https://stackoverflow.com/questions/26814426/how-to-convert-imagesource-to-byte-array) – NoWar Nov 09 '17 at 02:29

1 Answers1

2

If you have a BitmapSource you can use BitmapSource.CopyPixels Method (Array, Int32, Int32)

Or alternativeley, for example if you need a ARGB byte sequence:

var bmp = new WriteableBitmap((BitmapSource)source);
byte[] pixels = bmp.Pixels.SelectMany(p => new byte[]
{
    (byte)p,
    (byte)(p >> 8),
    (byte)(p >> 16),
    (byte)(p >> 24)
}).ToArray();
Nappy
  • 3,016
  • 27
  • 39