zoukankan      html  css  js  c++  java
  • Winform- 屏幕截屏

    使用WINFORM来进行屏幕截图,试试这一串

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            private int intStartX = 0;
            private int intStartY = 0;
            private bool isMouseDraw = false;
            private Rectangle rectangle;

            public Form1()
            {
                //this.BackColor = Color.Gray;
                //this.Opacity = 0.5;
                //this.FormBorderStyle = FormBorderStyle.None;
                //this.WindowState = FormWindowState.Maximized;

                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {

                Bitmap myImage = new Bitmap(rectangle.Width, rectangle.Height);
                Graphics g = Graphics.FromImage(myImage);

                //g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
                //g.CopyFromScreen(rectangle.X,rectangle.Y,(rectangle.X + rectangle.Width),
                //(rectangle.Y + rectangle.Height), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));

                g.CopyFromScreen(new Point(rectangle.X, rectangle.X), new Point(rectangle.X, rectangle.Y), new Size(rectangle.Width, rectangle.Height));

                myImage.Save(@"D:x.jpg");
                g.Dispose();



            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                isMouseDraw = true;
                intStartX = e.X;
                intStartY = e.Y;
            }

            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (isMouseDraw)
                {
                    try
                    {
                       
                        Graphics g = this.CreateGraphics();
                        //清空上次画下的痕迹
                        g.Clear(this.BackColor);
                        Brush brush = new SolidBrush(Color.Red);
                        Pen pen = new Pen(brush, 1);
                        pen.DashStyle = DashStyle.Solid;
                        rectangle = new Rectangle(intStartX > e.X ? e.X : intStartX, intStartY > e.Y ? e.Y : intStartY, Math.Abs(e.X - intStartX), Math.Abs(e.Y - intStartY));
                        g.DrawRectangle(pen, rectangle);
                        g.Dispose();
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
            }

            private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                isMouseDraw = false;

                intStartX = 0;
                intStartY = 0;
            }
        }
    }

  • 相关阅读:
    Dijkstra-leetcode 743.网络延迟时间
    BFS-leetcode787 K站中转内最便宜的航班
    图论基础——单源最短路径问题
    DFS leetcode-547 朋友圈
    SpringBoot 使用注解向容器中注册Bean的方法总结
    SpringBoot对SpringMVC的支持
    数据源简介
    Spring MVC简介
    2020-2-10 Python 列表切片陷阱:引用、复制与深复制
    2020-2-2 语法糖
  • 原文地址:https://www.cnblogs.com/cxeye/p/14240614.html
Copyright © 2011-2022 走看看