zoukankan      html  css  js  c++  java
  • 剪切图片(图形技术)

    界面:

    感觉没有什么地方需要解释。

    核心代码:

            bool isDrag = false;
            Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(0, 0));
            Point startPoint, oldPoint;
            private Graphics ig;

            private void button1_Click(object sender, EventArgs e)
            {
                openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
                openFileDialog1.ShowDialog();
                Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
                pictureBox1.Image = myImage;
            }

            private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    //如果开始绘制,则开始记录鼠标位置
                    if ((isDrag = !isDrag) == true)
                    {
                        startPoint = new Point(e.X, e.Y);
                        oldPoint = new Point(e.X, e.Y);
                    }
                }
            }

            private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            {
                isDrag = false;
                ig = pictureBox1.CreateGraphics();
                ig.DrawRectangle(new Pen(Color.Black, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y);
                theRectangle = new Rectangle(startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y);
            }

            private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                Graphics g = this.CreateGraphics();
                if (isDrag)
                {
                    g.DrawRectangle(new Pen(Color.Black, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y);
                }
            }

            private void Form1_MouseClick(object sender, MouseEventArgs e)
            {
                try
                {
                    Graphics graphics = this.CreateGraphics();
                    Bitmap bitmap = new Bitmap(pictureBox1.Image);
                    Bitmap cloneBitmap = bitmap.Clone(theRectangle, PixelFormat.DontCare);
                    graphics.DrawImage(cloneBitmap, e.X, e.Y);
                    Graphics g = pictureBox1.CreateGraphics();
                    SolidBrush myBrush = new SolidBrush(Color.White);
                    g.FillRectangle(myBrush, theRectangle);
                }
                catch
                { }
            }

  • 相关阅读:
    【邀请函】小投入 大产出—微软智能云(Azure)之CDN 专题
    Azure镜像市场再下一城,中标软件入驻开启Azure国产操作系统时代
    15分钟完成基于Azure公有云搭建远程测试环境
    独家秘笈!教你解锁移动应用新技能
    “剁手节”来了,红包你抢到了吗?
    Azure 11 月新公布
    面对故宫万千珍宝,升哲科技如何做到“朕知道了”
    高斯-克吕格投影
    cad定制快捷键
    matlab之scatter3()与plot3()函数
  • 原文地址:https://www.cnblogs.com/msAspnet/p/2098994.html
Copyright © 2011-2022 走看看