2010-06-10 49 views
1

我需要在我的位圖(Bgra32)上繪製基本形狀。但是,RenderTargetBitmap可以與Pbgra32位圖一起使用。在WPF中處理位圖的最優雅方式是什麼?如何處理WPF中的位圖?

回答

1

您可以定義構造函數本身你喜歡的任何格式的BitmapSource,然後發送給你想要的繪製一個字節數組。例如:

byte[] pixelData = DrawYourPicture(); 

int stride = width * PixelFormats.Pbgra32.BitsPerPixel/8; 
BitmapSource bmpSource = BitmapSource.Create(width, height, 96, 96, 
       PixelFormats.Pbgra32, null, pixelData, stride); 

然後可以將bmpSource直接分配給圖像的Source屬性。