Creates a new bitmap from a specific region of another bitmap
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace Isotope.ScreenCaptureLib
{
public static class DrawingUtil
{
/// <summary>
/// Creates a new bitmap from a specific region of another bitmap
/// </summary>
/// <param name="bmp_source"></param>
/// <param name="region"></param>
/// <returns></returns>
public static Bitmap CopyBitmap(Bitmap bmp_source, Rectangle region)
{
var bmp_dest = new Bitmap(region.Width, region.Height);
using (var g = Graphics.FromImage(bmp_dest))
{
g.DrawImage(bmp_source, 0, 0, region, GraphicsUnit.Pixel);
}
return bmp_dest;
}
}
}
Related examples in the same category