将System.Drawing.Bitmap复制到WriteableBitmap的区域中 [英] Copy a System.Drawing.Bitmap into a region of WriteableBitmap
本文介绍了将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的区域中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文