登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

面包会有的

... ...

 
 
 

日志

 
 

C# 截取指点区域的屏幕,并存为文件,同时在窗口中加载预览  

2016-10-21 00:04:49|  分类: C# |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
效果如图:
C 截取指点区域的屏幕,并存为文件,同时在窗口中加载预览 - 加菲 - 面包会有的
 

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



namespace CopyFromScreen
{
public partial class Form1 : Form
{


public Form1()
{
InitializeComponent();


}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
int width=0;//宽
int height = 0;//高
int x = 0;//起始点x坐标
int y = 0;//起始点y坐标

bool result1 = int.TryParse(this.textBox3.Text,out width);//从文本框获取值
bool result2 = int.TryParse(this.textBox4.Text,out height);
bool result3 = int.TryParse(this.textBox1.Text,out x);
bool result4 = int.TryParse(this.textBox2.Text,out y);

string ScreenshotPath = this.textBox5.Text;//存储路径

try
{
Image image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);

g.CopyFromScreen(x, y, 0, 0, new System.Drawing.Size(width, height));


string hour = DateTime.Now.Minute.ToString();
string second = DateTime.Now.Second.ToString();
string filepath = ScreenshotPath + "\\" + hour + "_" + second + ".jpg";//生成完整路径
image.Save(filepath);

this.pictureBox1.Image = Image.FromFile(@filepath);//显示到控件预览

}
catch
{

}
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("iexplore.exe", "http://wmnmtm.blog.163.com");
}

private void pictureBox1_Click(object sender, EventArgs e)
{

}
}
}



  评论这张
 
阅读(229)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018