Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When the Bitmap is loaded with Uri (jpeg or bmp file), the array resulting from CopyPixels, does not contains the pixels values.
C#
Uri uri = new Uri(path);
var bitmap = new BitmapImage(uri);
BitmapSource image = bitmap;
int bytesPerPixel = (int)Math.Truncate((image.Format.BitsPerPixel + 7.0) / 8.0);
int stride = image .PixelWidth * bytesPerPixel;
int len = image.PixelHeight * stride;
byte[] pixels = new byte[len];
image.CopyPixels(pixels, stride, 0);


What I have tried:

use jpeg encoder
C#
JpegBitmapDecoder jpegDecoder = new JpegBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
BitmapFrame BmpFrame = jpegDecoder.Frames[0];


try to get pixels from BmpFrame, no success again
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900