2010-06-10 50 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属性。