目前实现如下功能: 
1,随鼠标在图片上的移动会出现一个半透明的框,框内的部分即为截取的部分,双击即可获得截取部分 
2,支持自定义选择框的大小(设置size属性) 
3,支持自定义选择框的颜色(设置画刷brush属性) 
4,支持鼠标滚轮缩放图片 
5,支持设置缩放步进幅度(step属性) 
6,支持设置缩放范围(scale属性)【注:此百分比以开始截图时(start方法)图片控件内图片的大小为基准】 
7,支持截图后执行自定义的方法(注册Capture事件) 
8,事件参数包含了截图完成后的图片对象和错误错误描述基本使用 
1,把ImageCapture对象设置为窗体级别变量,以便重复调用 
2,窗体加载即实例化ImageCapture对象 
3,注册截图完成事件(Capture) 
4,自定义属性(可选) 
5,执行Start方法,初始化截图器 
6,双击截图,自动执行注册给Capture事件的方法 
7,如果重新截图,需要再次执行Start方法为什么不可以连续截图? 
Start方法是为了重置截图前部分属性,以后有好的方案可能会优化这个不足之处 
同样,因为Start方法的使用和本算法的小问题,在把picturebox里面的图片缩小后如果再调用一次Start方法,则会把当前图片大小当成100%大小作为基数来进行缩放,这也是小bug一枚。另。关于缩放的算法借用了网上的成熟算法,没有深入研究和优化,拿来主义,同时年代久远也已经不知道作者了。做了个测试程序一枚,文后示例代码(C#教程)简单示例:?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void onload()
{
    //实例化变量
    ImageCapture img = new ImageCapture(pictureBox1);
    //注册事件
    img.Capture += new ImageCapture.CaptureEventHandler(img_Capture);
    //启动截图器
    img.Start();
}
void img_Capture(object sender, ImageCapture.CaptureEventArgs e)
{
    if (null != e.Value)
    {
        //得到截图后自行处理
        pictureBox2.Image = e.Value;
    }
    else
    {
        MessageBox.Show(e.Message);
    }
}

解决方案 »

  1.   

    参考一下老大做的截图
    http://www.cnblogs.com/zhouyinhui/archive/2010/08/20/1804762.html
      

  2.   

    给你个类public class ScreenShot
    {
    [DllImport("gdi32.dll")]
    private static extern IntPtr CreateDC(
    string lpszDriver,        // driver name
    string lpszDevice,        // device name
    string lpszOutput,        // not used; should be NULL
    Int32 lpInitData          // optional printer data
    );
     
    [DllImport("gdi32.dll")]
    private static extern IntPtr CreateCompatibleDC(
    IntPtr hdc // handle to DC
    );
     
    [DllImport("gdi32.dll")]
    private static extern int GetDeviceCaps(
    IntPtr hdc,     // handle to DC
    int nIndex   // index of capability
    );
    [DllImport("gdi32.dll")]
    private static extern IntPtr CreateCompatibleBitmap(
    IntPtr hdc,        // handle to DC
    int nWidth,     // width of bitmap, in pixels
    int nHeight     // height of bitmap, in pixels
    );
    [DllImport("gdi32.dll")]
    private static extern IntPtr SelectObject(
    IntPtr hdc,          // handle to DC
    IntPtr hgdiobj   // handle to object
    ); [DllImport("gdi32.dll")]
    private static extern int BitBlt(
    IntPtr hdcDest, // handle to destination DC
    int nXDest,  // x-coord of destination upper-left corner
    int nYDest,  // y-coord of destination upper-left corner
    int nWidth,  // width of destination rectangle
    int nHeight, // height of destination rectangle
    IntPtr hdcSrc,  // handle to source DC
    int nXSrc,   // x-coordinate of source upper-left corner
    int nYSrc,   // y-coordinate of source upper-left corner
    UInt32 dwRop  // raster operation code
    );
    [DllImport("gdi32.dll")]
    private static extern int DeleteDC(
    IntPtr hdc          // handle to DC
    ); ///--------------------------------------------------------------------
    /// <summary>
    /// Get the screen shot to a bmp file.
    /// </summary>
    /// <param name="fileName">File name for the bmp file. Could have path.
    /// </param>
    /// <returns>Void</returns>
    /// <exception cref="Exception">Thrown if an exception occurs.</exception>
    /// <history>
    ///  [ericx] 11/09/2005 Created
    /// </history>
    ///--------------------------------------------------------------------
    public static void SaveScree(string fileName)
    {
    IntPtr hdc;
    IntPtr hmemdc;
    IntPtr hbitmap;
    Bitmap bmp = null; int xscrn = 0;
    int yscrn = 0; if (File.Exists(fileName))
    {
    File.Delete(fileName);
    } hdc = CreateDC("DISPLAY", null, null, 0);
    hmemdc = CreateCompatibleDC(hdc);//memory DC xscrn = GetDeviceCaps(hdc, 8);//HORZRES);
    //screenwidth
    yscrn = GetDeviceCaps(hdc, 10);//GetDeviceCapsIndex.VERTRES);
    //screenHeight hbitmap = CreateCompatibleBitmap(hdc, xscrn, yscrn); SelectObject(hmemdc, hbitmap); BitBlt(hmemdc, 0, 0, xscrn, yscrn, hdc, 0, 0,(UInt32)0xcc0020); bmp = Bitmap.FromHbitmap(hbitmap);
    bmp.Save(fileName); DeleteDC(hdc);
    DeleteDC(hmemdc);
    }        ///--------------------------------------------------------------------
    /// <summary>
    /// Get screen shot when the error occur. Used a int seed
    /// to avoid the same fileName;
    /// </summary>
    /// <param name="caseName">This name use to define the save bmp file
    /// name. So we must make sure this name is unique.</param>
    /// <param name="path">This is the file path. But if we set path null,
    /// the function will suppose the path is current directory.</param>
    /// <returns>Void</returns>
    /// <exception cref="Exception">No exception.</exception>
    /// <history>
    ///  [ericx] 11/09/2005 Created
    /// </history>
    ///--------------------------------------------------------------------
    public static void GetErrorScreenShot(string caseName, string path)
    {
    try
    {
    if (path == null)
    {
    path = "";
    } string fileName = Path.Combine(path, caseName + "_ErrorScree"); int seed = 0; while (File.Exists(fileName + seed))
    {
    seed ++;
    } SaveScree(fileName + seed + ".bmp");
    }
    catch
    {
    }
    }
    }