C#复制粘贴图像区域到另一个图像
问题描述:
我想写一个实用程序类,允许tilebale图像的自动调整大小。假设有一个srcBitmap,我从中复制了由Rectangle srcRegion给出的区域。然后,我想将该区域粘贴(像素信息明智)到另一个名为Bitmap destBitmap的图像中,位于目标区域Rectangle destRegion中。 我知道如何从源代码获取区域并将其放入Bitmap对象,但我还没有找到如何实际将Bitmap对象粘贴到另一个较大的Bitmap对象的某个区域中。C#复制粘贴图像区域到另一个图像
有没有快速的方法来做到这一点? (没有GDI,也没有钻研Bitmaps的字节数组)。下面是应该明确自己的目标
private static void CopyRegionIntoImage(Bitmap srcBitmap, Rectangle srcRegion, Bitmap destBitmap, Rectangle destRegion)
{
// get the required region from the destination
Bitmap region = Copy(srcBitmap, srcRegion);
}
答
使用片断这样的:
public static void CopyRegionIntoImage(Bitmap srcBitmap, Rectangle srcRegion,ref Bitmap destBitmap, Rectangle destRegion)
{
using (Graphics grD = Graphics.FromImage(destBitmap))
{
grD.DrawImage(srcBitmap, destRegion, srcRegion, GraphicsUnit.Pixel);
}
}
您已经在使用GDI +与Bitmap类。 – dvdvorle 2012-03-08 11:10:38
谢谢!我想.NET 4.0框架在这个库的周围有包装。没有意识到它,C#和dotNet不是我的面包和黄油。 – teodron 2012-03-08 12:01:35