截取全屏代码:

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) 收藏的更多相关文章

  1. 棋盘问题 分类: 搜索 POJ 2015-08-09 13:02 4人阅读 评论(0) 收藏

    棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28474 Accepted: 14084 Description 在一 ...

  2. 【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 ...

  3. TinyXML2读取和创建XML文件 分类: C/C++ 2015-03-14 13:29 94人阅读 评论(0) 收藏

    TinyXML2是simple.small.efficient C++ XML文件解析库!方便易于使用,是对TinyXML的升级改写!源码见本人上传到CSDN的TinyXML2.rar资源:http: ...

  4. 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 ...

  5. 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 ...

  6. 积分图像的应用(一):局部标准差 分类: 图像处理 Matlab 2015-06-06 13:31 137人阅读 评论(0) 收藏

    局部标准差在图像处理邻域具有广泛的应用,但是直接计算非常耗时,本文利用积分图像对局部标准差的计算进行加速. 局部标准差: 标准差定义如下(采用统计学中的定义,分母为): 其中. 为了计算图像的局部标准 ...

  7. C# WinForm 透明控件 PictureBox透明 分类: WinForm 2014-07-30 13:27 591人阅读 评论(0) 收藏

    1.要实现C# WinForm中的控件与背景的透明,可以通过设置控件的BackColor属性为Transparent,同时设置其父控件.因为在C#中,控件的透明指对父窗体透明.如果不设置Parent属 ...

  8. winform datagridview如何获取索引 分类: DataGridView 2014-04-11 13:42 216人阅读 评论(0) 收藏

    datagridview.CurrentCell.RowIndex;            是当前活动的单元格的行的索引 datagridview.SelectedRows  ;           ...

  9. iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏

    youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...

随机推荐

  1. ToString函数用法

    // C 货币    2.5.ToString("C"); // ¥2.50    // D 10进制数    25.ToString("D5"); // 25 ...

  2. WF学习笔记(三)

    Collection 集合 -AddtoCollection<T> 添加项到集合 :[AddtoCollection]可以将一个项添加到[Collection]集合中 ,[Item]属性用 ...

  3. 不同的路径 II

    class Solution { public: /** * @param obstacleGrid: A list of lists of integers * @return: An intege ...

  4. CodeIgniter框架介绍

    入口 index.php :一些路径常量定义: => CodeIgniter.php : 1. 初始化一些 system/core内的类,例如Config, Utf8, URI 和Router等 ...

  5. C语言中float,double类型,在内存中的结构(存储方式)

    C语言中float,double类型,在内存中的结构(存储方式)从存储结构和算法上来讲,double和float是一样的,不一样的地方仅仅是float是32位的,double是64位的,所以doubl ...

  6. Successfully installed matplotlib

    Installing /usr/local/lib/python2.7/dist-packages/matplotlib-1.4.0-py2.7-nspkg.pthSuccessfully insta ...

  7. 第一个deeplearning4jproject跑起

    deeplearning4j是基于java的深度学习库,当然,它有许多特点,但暂时还没学那么深入,所以就不做介绍了 需要学习dl4j,无从下手,就想着先看看官网的examples,于是,下载了exam ...

  8. hadoop 学习笔记 (十) mapreduce2.0

    MapReduce的特色---不擅长的方面 >实时计算 像mysql一样,在毫秒级或者秒级内返回结果 >流式计算 Mapreduce的输入数据时静态的,不能动态变化 MapReduce自身 ...

  9. matplotlib 绘图

    http://blog.csdn.net/jkhere/article/details/9324823 都打一遍 5 matplotlib-绘制精美的图表 matplotlib 是python最著名的 ...

  10. ZOOKEEPER在CENTOS6上的再安装

    作DUBBO时,肯定是需要的,,对的,,DUBBO也要熟悉一下才行啦.. URL: http://www.centoscn.com/CentosServer/test/2015/0120/4531.h ...