1
我有以下功能,在Windows窗體中工作,但我需要幫助,使其工作在WPF與圖像控制。什麼是WPF的等價函數?
public static Bitmap CreateBitmap(byte[] bytes, int width, int height)
{
var rgbBytes = new byte[bytes.Length * 3];
for (var i = 0; i <= bytes.Length - 1; i++)
{
rgbBytes[(i * 3)] = bytes[i];
rgbBytes[(i * 3) + 1] = bytes[i];
rgbBytes[(i * 3) + 2] = bytes[i];
}
var bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
for (var i = 0; i <= bmp.Height - 1; i++)
{
var p = new IntPtr(data.Scan0.ToInt32() + data.Stride * i);
System.Runtime.InteropServices.Marshal.Copy(rgbBytes, i * bmp.Width * 3, p, bmp.Width * 3);
}
bmp.UnlockBits(data);
return bmp;
}
任何幫助將不勝感激。 感謝
那究竟是不是工作? – nvoigt
考慮使用[WriteableBitmap](http://msdn.microsoft.com/zh-cn/library/system.windows.media.imaging.writeablebitmap%28v=vs.110%29.aspx)。 –
在WPF中無法識別PixelFormat.Format24bppRgb – Laskar78