Can anybody suggest how I can convert an image to a byte array and vice versa?
I\'m developing a WPF application and using a stream reader.
Do you only want the pixels or the whole image (including headers) as an byte array?
For pixels: Use the CopyPixels
method on Bitmap. Something like:
var bitmap = new BitmapImage(uri);
//Pixel array
byte[] pixels = new byte[width * height * 4]; //account for stride if necessary and whether the image is 32 bit, 16 bit etc.
bitmap.CopyPixels(..size, pixels, fullStride, 0);