• c#图片截取DEMO


    截图DEMO
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Imaging;
    
    namespace 图片截图
    {
        public partial class Form1 : Form
        {
    
            bool isDrag = false;
            Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(0, 0));
            Point startPoint, oldPoint;
            private Graphics ig;
    
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
    
            }
    
            private void button2_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_MouseClick(object sender, MouseEventArgs e)
            {
                 try
                {
                    //Graphics graphics = this.CreateGraphics();
                    Bitmap bitmap = new Bitmap(pictureBox1.Image);
                    Bitmap cloneBitmap = bitmap.Clone(theRectangle, PixelFormat.DontCare);
                    pictureBox2.Image = (Image)cloneBitmap;
                    //graphics.DrawImage(cloneBitmap, e.X, e.Y);
                    Graphics g = pictureBox1.CreateGraphics();
                    SolidBrush myBrush = new SolidBrush(Color.Transparent);
                    g.FillRectangle(myBrush, theRectangle);
                }
                catch
                { }
            }
        }
    }
  • 相关阅读:
    sklearn各种分类器简单使用
    使用Pandas加载数据
    使用Sklearn-train_test_split 划分数据集
    KNN_python
    ga算法
    粒子群算法
    bp神经网络的实现C++
    理解RNN
    感知器的实现C++
    线性神经网络的实现C++
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/2819014.html
Copyright © 2020-2023  润新知