如何处理WPF中的位图?

时间:2010-06-10 12:10:43

标签: c# wpf bitmap

我需要在我的位图(Bgra32)上绘制基本形状。但是,RenderTargetBitmap与Pbgra32位图一起使用。在WPF中处理位图的最优雅方法是什么?

1 个答案:

答案 0 :(得分: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直接分配给Image的Source属性。