zoukankan      html  css  js  c++  java
  • 剪切图像

    实现效果:

      

    知识运用:

      Bitmap类的Clone方法        //创建Bitmap对象的 某个部分 的副本

      public Bitmap Clone  (Rectangle rect, PixelFormat format)  //由Rectangle结构和指定的PixelFormat枚举定义

      Graphics类的FillRectangle方法    //填充Rectangle结构指定的矩形的内部

      public void FillRectangle (Brush brush, Rectangle rect)

    实现代码:

            private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                        startPt = new Point(e.X, e.Y);
                }
            }
    
            private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            {
                    ig = pictureBox1.CreateGraphics();
                    rectangle = new Rectangle(startPt.X, startPt.Y, e.X-startPt.X, e.Y-startPt.Y);
                    ig.DrawRectangle(new Pen(Color.Black, 1), rectangle);
            }
    
            private void Form1_MouseClick(object sender, MouseEventArgs e)
            {
                try
                {
                    Graphics g = this.CreateGraphics();
                    Bitmap bmp = new Bitmap(pictureBox1.Image);
                    Bitmap cutBmp = bmp.Clone(rectangle,System.Drawing.Imaging.PixelFormat.DontCare);
                    g.DrawImage(cutBmp,e.X,e.Y);
                    SolidBrush myBrush = new SolidBrush(Color.Wheat);
                    ig.FillRectangle(myBrush,rectangle);
                }
                catch{}
            }
    

      

  • 相关阅读:
    mybatis入门-1
    try-with-resources 在捕获异常之后自动释放资源 try(){}
    mybatis配置logback
    使用原生的jdbc连接数据库进行查询
    java中的反射
    ajax实现搜索自动补全
    java IO-1 File 2019-07-24
    VMware历史版本
    Centos8.3-NIS
    用户管理
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10261721.html
Copyright © 2011-2022 走看看