private Bitmap bt1; 
        private Bitmap bt2; 
        Point p1; 
        Point p2; 
        bool b = false; 
        Image img; 
        /// <summary> 
        /// 剪切图片的按钮 
        /// </summary> 
        /// <param name="sender"> </param> 
        /// <param name="e"> </param> 
        private void btnShear_Click(object sender, EventArgs e) 
        { 
            b = true; 
        }         /// <summary> 
        /// 获取按下鼠标指针的坐标 
        /// </summary> 
        /// <param name="sender"> </param> 
        /// <param name="e"> </param> 
        private void pictureBox_MouseDown(object sender, MouseEventArgs e) 
        { 
            if (b) 
            { 
                this.Cursor = Cursors.Cross; 
                p1 = new Point(e.X, e.Y); 
            } 
        }         /// <summary> 
        /// 记录鼠标的移动 
        /// </summary> 
        /// <param name="sender"> </param> 
        /// <param name="e"> </param> 
        private void pictureBox_MouseMove(object sender, MouseEventArgs e) 
        { 
            if (b) 
            { 
                if (this.Cursor == Cursors.Cross) 
                {                  
                    p2 = new Point(e.X, e.Y); 
                    pictureBox.Refresh(); 
                    Pen p = new Pen(Color.White, 1); 
                    p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; 
                    Rectangle rect = new Rectangle(p1, new Size(p2.X - p1.X, p2.Y - p1.Y)); 
                    Graphics _Graphcis = Graphics.FromHwnd(pictureBox.Handle); 
                    _Graphcis.DrawRectangle(p, rect); 
                    _Graphcis.Dispose(); 
                    p.Dispose(); 
                    
                } 
            } 
        }         /// <summary> 
        /// 获取松开鼠标时指针的坐标 
        /// </summary> 
        /// <param name="sender"> </param> 
        /// <param name="e"> </param> 
        private void pictureBox_MouseUp(object sender, MouseEventArgs e) 
        { 
            if (b) 
            {                 this.Cursor = Cursors.Default; 
                p2 = new Point(e.X, e.Y); 
                CutImage(); 
                pictureBox.Refresh(); 
                b = false; 
            } 
        }         /// <summary> 
        /// 剪切图片 
        /// </summary> 
        private void CutImage() 
        { 
            try 
            { 
                img = this.pictureBox.Image; 
                bt1 = new Bitmap(p2.X - p1.X, p2.Y - p1.Y); 
                Rectangle tgtRect = new Rectangle(0, 0, bt1.Width, bt1.Height); 
                Rectangle srcRect = new Rectangle(p1.X, p1.Y, bt1.Width, bt1.Height); 
                Graphics g = Graphics.FromImage(bt1); 
                g.DrawImage(img, tgtRect, srcRect, GraphicsUnit.Pixel); 
                this.pictureBox.Image = bt1;                 g.Dispose(); 
            } 
            catch (Exception) 
            {             } 
        } 

解决方案 »

  1.   

    我建议使用3层bitmap来做 bitmap1 绘制鼠标移动的矩形 
    bitmap2 实际被剪切的图像,不会被修改 
    bitmap3 在这一层里先绘制bitmap2,再绘制bitmap1,然后赋值给pictureBox显示。 绘制的频率使用timer控制就可以。
      

  2.   

    就是在picturebox里面剪切图片时,当鼠标松改执行剪切后,剪切出来的图片的坐标没动,还是在原来的地方
      

  3.   

    第一个方法 要么你创建一个和原来一样大的图..把你剪切的图贴到原来的位置上第二个方法 改变PictureBox到相应的大小和位置第三个方法 在PictureBox Paint里绘制 图形绘制到相应的位置.