1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Uri uri = new Uri(name);
BmpBitmapDecoder decoder = new BmpBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bmpI = decoder.Frames[0];
WriteableBitmap bmp = new WriteableBitmap(bmpI);
if (bmpI.Format == PixelFormats.Indexed8)
{
pixels = new int[(int)(4 * bmpI.Height * bmpI.Width)];
bmpI.CopyPixels(pixels, (int)(4 * bmpI.Width), 0);
}
if (bmpI.Format == PixelFormats.Bgr24)
{
//MessageBox.Show(bmpI.Height.ToString()+" "+bmpI.Width.ToString());
pixels = new int[(int)(4 * bmpI.Height * bmpI.Width)];
bmpI.CopyPixels(pixels, (int)(4 * bmpI.Width), 0);
} |
Partager