本文介绍了将System.Drawing.Bitmap复制到WriteableBitmap的区域中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前在将System.Drawing.Bitmap集成到WPF WriteableBitmap中时遇到一些问题.
I'm currently having some problems in integrating a System.Drawing.Bitmap into a WPF WriteableBitmap.
我想从Bitmap复制到WriteableBitmap的(X,Y)位置.
I want to copy from the Bitmap to position (X,Y) of the WriteableBitmap.
以下代码显示了我如何尝试执行此操作.
The following code shows how I've tried to do this.
BitmapData Data = Bitmap.LockBits(new Rectangle(0, 0, Bitmap.Width, Bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); WriteableBitmap.Lock(); //CopyMemory(WriteableBitmap.BackBuffer, Data.Scan0, ImageBufferSize); Int32Rect Rect = new Int32Rect(X, Y, Bitmap.Width, Bitmap.Height); WriteableBitmap.AddDirtyRect(Rect); Bitmap.UnlockBits(Data); Bitmap.Dispose();`非常感谢
Neokript
推荐答案使用WritableBitmap.WritePixels.这样可以避免使用非托管代码.
Use WritableBitmap.WritePixels. This will prevent using unmanaged code.
BitmapData Data = Bitmap.LockBits(new Rectangle(0, 0, Bitmap.Width, Bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); try { WritableBitmap.WritePixels( new Int32Rect(0,0,Bitmap.Width, Bitmap.Height), Data.Scan0, Data.Stride, X, Y); } finally { Bitmap.UnlockBits(Data); } Bitmap.Dispose();更多推荐
将System.Drawing.Bitmap复制到WriteableBitmap的区域中
发布评论