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

  • 相关阅读:
    献给需要购买 阿里云产品的朋友
    当硬件没问题的时候,提升电脑运行速度
    IIS网页GZIP压缩
    前端优化-如何计算白屏和首屏时间
    Javascript 思维导图
    总结get和post区别---面试用
    点击切换样式、以及点击自身移除样式效果
    各行换色
    计算器
    无缝轮播图
  • 原文地址:https://www.cnblogs.com/cxeye/p/14240614.html
Copyright © 2011-2022 走看看