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{}
            }
    

      

  • 相关阅读:
    Express入门
    nodejs入门
    css实现点点点效果
    定时器详解和应用、js加载阻塞、css加载阻塞
    栈内存和堆内存有什么区别?
    webpack入门
    Ubuntu常用命令集合
    HTTP缓存机制
    125. 验证回文字符串
    算法的时间复杂度和空间复杂度(js版)
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10261721.html
Copyright © 2011-2022 走看看