BitmapSource copypixels method does not return rgb pixels data

257 Views Asked by At

I'm readying pixel data from a PNG BitmapSource using CopyPixels method. However the read call into array does not return the pixel data.

Any reason why this would happen ?

I have included the image below

PNG Sample

Edit:

Byte array doesn't contain the RGB pixel data. Array just contains value 0 for each index item.

Code:

using(FileStream stream = new FileStream(strImageFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
    {
        if (stream.Length > 0)
        {
            BitmapDecoder bmpDecoder = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

            BitmapSource bmpSourceFrame = bmpDecoder.Frames[0];

            int iStride = bmpSourceFrame.PixelWidth * ((bmpSourceFrame.Format.BitsPerPixel + 7) / 8);
            byte[] bytImage = new byte[iStride * bmpSourceFrame.PixelHeight];

            bmpSourceFrame.CopyPixels(bytImage, iStride, 0);
        }
     }
0

There are 0 best solutions below