Exemplo n.º 1
0
        /// <summary>
        /// 鼠标抬起,结束截图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cutter_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (Is_CatchStart)
                {
                    Is_CatchStart = false;
                    if (CatchRectangle.Width == 0 || CatchRectangle.Height == 0)
                    {
                        return;
                    }
                    Bitmap   CatchedBmp = new Bitmap(CatchRectangle.Width, CatchRectangle.Height);
                    Graphics g          = Graphics.FromImage(CatchedBmp);

                    // 把originBmp中指定部分按照指定大小画到空白图片上
                    // CatchRectangle指定originBmp中指定部分
                    // 第二个参数指定绘制到空白图片的位置和大小
                    // 画完后CatchedBmp不再是空白图片了,而是具有与截取的图片一样的内容
                    g.DrawImage(WinBmp, new Rectangle(0, 0, CatchRectangle.Width, CatchRectangle.Height), CatchRectangle, GraphicsUnit.Pixel);
                    // 将图片保存到剪切板中
                    Clipboard.Clear();
                    Clipboard.SetImage(CatchedBmp);
                    g.Dispose();
                    retBitmap = CatchedBmp;
                    WinBmp.Dispose();
                    CatchedBmp.Dispose();
                    this.CanRead = true;
                    this.Close();
                }
            }
        }