winfrom 截屏、抓屏 分类: WinForm 2014-08-01 13:02 198人阅读 评论(0) 收藏
截取全屏代码:
try
{
this.Hide();
Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size); System.Threading.Thread.Sleep(50); SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp files (*.bmp)|*.bmp";
saveFileDialog.Title = "保存文件";
saveFileDialog.ShowDialog();
bmpPath = saveFileDialog.FileName;
if ("" != bmpPath)
{
bitmap.Save(bmpPath, ImageFormat.Bmp);
}
bitmap.Dispose();
this.Show();
}
catch (System.Exception ex)
{
MessageBox.Show("抓图失败!");
this.Show();
}
frmChildScreen 窗体代码如下:
private void frmChildScreen_Load(object sender, EventArgs e)
{
this.Cursor = Cursors.Cross; this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
this.UpdateStyles();
originBmp = new Bitmap(this.BackgroundImage);
} private void Catch_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (!catchStart)
{
catchStart = true;
startPoint = new Point(e.X, e.Y);
}
}
} private void Catch_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
} private void Catch_MouseMove(object sender, MouseEventArgs e)
{
if (catchStart)
{
Bitmap destBmp = (Bitmap)originBmp.Clone();
Point newPoint = new Point(startPoint.X, startPoint.Y);
Graphics g = Graphics.FromImage(destBmp);
Pen p = new Pen(Color.Blue, 1);
int width = Math.Abs(e.X - startPoint.X), height = Math.Abs(e.Y - startPoint.Y);
if (e.X < startPoint.X)
{
newPoint.X = e.X;
}
if (e.Y < startPoint.Y)
{
newPoint.Y = e.Y;
}
catchRect = new Rectangle(newPoint, new Size(width, height));
g.DrawRectangle(p, catchRect);
g.Dispose();
p.Dispose();
Graphics g1 = this.CreateGraphics();
g1 = this.CreateGraphics();
g1.DrawImage(destBmp, new Point(0, 0));
g1.Dispose();
destBmp.Dispose();
}
} private void Catch_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (catchStart)
{
catchStart = false;
catchFinish = true;
}
}
} private void Catch_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && catchFinish)
{
if (catchRect.Contains(new Point(e.X, e.Y)))
{
Bitmap bitmap = new Bitmap(catchRect.Width, catchRect.Height);
Graphics g = Graphics.FromImage(bitmap);
g.DrawImage(originBmp, new Rectangle(0, 0, bitmap.Width, bitmap.Height), catchRect, GraphicsUnit.Pixel); SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp files (*.bmp)|*.bmp";
saveFileDialog.Title = "保存文件";
saveFileDialog.ShowDialog();
bmpPath = saveFileDialog.FileName;
if ("" != bmpPath)
{
bitmap.Save(bmpPath, ImageFormat.Bmp);
}
bitmap.Dispose();
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}
截取局部屏幕代码如下:
try
{
this.Hide();
Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
Thread.Sleep(50);
frmChildScreen CatchForm = new frmChildScreen();
Bitmap catchBmp = new Bitmap(bounds.Width, bounds.Height);
Graphics g = Graphics.FromImage(catchBmp);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));
CatchForm.BackgroundImage = catchBmp;
if (CatchForm.ShowDialog() == DialogResult.OK)
{
this.Show();
}
}
catch (System.Exception e)
{
MessageBox.Show("抓图失败!");
this.Show();
}
winfrom 截屏、抓屏 分类: WinForm 2014-08-01 13:02 198人阅读 评论(0) 收藏的更多相关文章
- 棋盘问题 分类: 搜索 POJ 2015-08-09 13:02 4人阅读 评论(0) 收藏
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28474 Accepted: 14084 Description 在一 ...
- 【Heritrix基础教程之2】Heritrix基本内容介绍 分类: B1_JAVA H3_NUTCH 2014-06-01 13:02 878人阅读 评论(0) 收藏
1.版本说明 (1)最新版本:3.3.0 (2)最新release版本:3.2.0 (3)重要历史版本:1.14.4 3.1.0及之前的版本:http://sourceforge.net/projec ...
- TinyXML2读取和创建XML文件 分类: C/C++ 2015-03-14 13:29 94人阅读 评论(0) 收藏
TinyXML2是simple.small.efficient C++ XML文件解析库!方便易于使用,是对TinyXML的升级改写!源码见本人上传到CSDN的TinyXML2.rar资源:http: ...
- Segment Tree 分类: ACM TYPE 2014-08-29 13:04 97人阅读 评论(0) 收藏
#include<iostream> #include<cstdio> using namespace std; struct node { int l, r, m; int ...
- JAVA swing中JPanel如何实现分组框的效果以及设置边框颜色 分类: Java Game 2014-08-16 12:21 198人阅读 评论(0) 收藏
代码如下: import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GridLayout; import javax.sw ...
- 积分图像的应用(一):局部标准差 分类: 图像处理 Matlab 2015-06-06 13:31 137人阅读 评论(0) 收藏
局部标准差在图像处理邻域具有广泛的应用,但是直接计算非常耗时,本文利用积分图像对局部标准差的计算进行加速. 局部标准差: 标准差定义如下(采用统计学中的定义,分母为): 其中. 为了计算图像的局部标准 ...
- C# WinForm 透明控件 PictureBox透明 分类: WinForm 2014-07-30 13:27 591人阅读 评论(0) 收藏
1.要实现C# WinForm中的控件与背景的透明,可以通过设置控件的BackColor属性为Transparent,同时设置其父控件.因为在C#中,控件的透明指对父窗体透明.如果不设置Parent属 ...
- winform datagridview如何获取索引 分类: DataGridView 2014-04-11 13:42 216人阅读 评论(0) 收藏
datagridview.CurrentCell.RowIndex; 是当前活动的单元格的行的索引 datagridview.SelectedRows ; ...
- iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏
youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...
随机推荐
- Observer 模式
Observer模式要解决的问题为:建立一个一(Subject)对多(Observer)的依赖关系,并且做到当“一”变化的时候,依赖这个“一”的多也能够同步改变.最常见的一个例子就是:对同一组数据进行 ...
- mongo数据库使用小结
db.userId5555.aggregate({$unwind:"$tcjl"},{$match:{"_id":"0e549864-2a56-43c ...
- 从网页psd到html的开发
从网上下载了一张psd的网页设计稿,初学html+css,所以记录一下我的学习过程.原图是这个样子: 原图 ...
- #Leet Code# Divide Two Integers
描述:不使用 * / % 完成除法操作.O(n)复杂度会超时,需要O(lg(n))复杂度. 代码: class Solution: # @return an integer def dividePos ...
- Model Thinking1
Why Model Reason # 1: Intelligent Citizen of the World Reason # 2: Clearer Thinker Reason # 3: Under ...
- codevs 1557 热浪
传送门 题目描述 Description 德克萨斯纯朴的民眾们这个夏天正在遭受巨大的热浪!!!他们的德克萨斯长角牛吃起来不错,可是他们并不是很擅长生產富含奶油的乳製品.Farmer John此时以先天 ...
- Unity3D 解决c#脚本乱码
怀着无比激动的心情下载了Unity3D,按照网上的教程试着制作我的第一个U3D"作品":camera绑定绘制GUI显示"Hello, World",很简单的例子 ...
- Phonegap 3.0 设置APP是否全屏
Phonegap 3.0 默认是全屏,如需要取消全屏,可手动修改config, 在APP/res/xml/config.xml文件可设置preference: <?xml version='1. ...
- 【HDU4859】 海岸线(网络流-最小割)
Problem Description 欢迎来到珠海! 由于土地资源越来越紧张,使得许多海滨城市都只能依靠填海来扩展市区以求发展.作为Z市的决策人,在仔细观察了Z市地图之后,你准备通过填充某些海域来扩 ...
- asp.net关于Cookie跨域(域名)的问题
Cookie是一个伟大的发明,它允许Web开发者保留他们的用户的登录状态.但是当你的站点有一个以上的域名时就会出现问题了.在Cookie规范上 说,一个cookie只能用于一个域名,不能够发给其它的域 ...