将System.Drawing.Bitmap复制到WriteableBitmap的区域中

编程入门 行业动态 更新时间:2024-10-24 08:20:45
本文介绍了将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的区域中

本文发布于:2023-10-04 04:50:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467120.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区域   Drawing   System   WriteableBitmap   Bitmap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!