截图工具

图2

截图工具

有段时间公司没网了,写文档要用截图,无法使用心爱的QQ截图了,就自己写了个截图工具,bug有点,没有修复,能用,类似QQ截图,差不多,还蛮好用的,有网以后,就没怎么用了,把代码共享出来

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.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace ScreenCapture
{
    public partial class frmScreen : Form
    {
        public frmScreen()
        {
            InitializeComponent();
        }
        private Point startPoint = Point.Empty;
        private Point endPoint = Point.Empty;
        public Rectangle rect = Rectangle.Empty;

        private void frmScreen_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) {
                this.startPoint = e.Location;
            }
        }

        private void frmScreen_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.endPoint = e.Location;
                Graphics grp = this.CreateGraphics();

                rect = new Rectangle();
                rect.X = (this.startPoint.X <= this.endPoint.X) ? this.startPoint.X : this.endPoint.X;
                rect.Y = (this.startPoint.Y <= this.endPoint.Y) ? this.startPoint.Y : this.endPoint.Y;
                rect.Width = Math.Abs(this.endPoint.X-this.startPoint.X);
                rect.Height = Math.Abs(this.endPoint.Y - this.startPoint.Y);
                grp.Clear(this.BackColor);
                Rectangle border = new Rectangle(); //这个是边框矩形
                border.X = rect.X - 1;
                border.Y = rect.Y - 1;
                border.Width = rect.Width;
                border.Height = rect.Height;
                grp.DrawRectangle(Pens.Blue, border);
                grp.FillRectangle(Brushes.Red, rect);

            }
        }

        private void frmScreen_MouseUp(object sender, MouseEventArgs e)
        {
            Bitmap bitmap = new Bitmap(this.rect.Width,this.rect.Height);
            Graphics grp = Graphics.FromImage(bitmap);
            grp.SmoothingMode = SmoothingMode.HighQuality;
            //从指定的区域中复制图形
            grp.CopyFromScreen(this.rect.X, this.rect.Y, 0, 0, this.rect.Size);
           ImageFormat format=ImageFormat.Jpeg;
           saveFile.Filter = "图片|*.jpg";
           saveFile.ShowDialog();
           string strfile = saveFile.FileName;
           bitmap.Save(strfile);
            this.Close();
            MessageBox.Show("截图成功");
        }
    }
}

github代码下载:https://github.com/zy20081/practice.git


转载请注明: Zhou•Yong 截图工具

上一篇
代码生成器 代码生成器
代码生成器这是我读书时期,学C#,每次写上机练习,都要写3层架构,练增删改查,那个时候还不流行动软生成器和CodeSmith,所以就根据自己的写代码方式,写了个自己常用的代码生成器生成3层架构,这个要配合我写的SqlHelper一起使用
2019-01-10
下一篇
C#之Socket C#之Socket
C#中Socket的简单使用 服务端监听某个端口 客户端向服务端地址和端口发起Socket连接请求 服务端收到连接请求后创建Socket连接,并维护这个连接队列。 客户端和服务端已经建立双工通信(即双向通信),客户端和服务端可以轻松方便的给
2019-01-09
目录