文档详情

C鼠标选择框截图代码.doc

发布:2017-02-05约6.39千字共6页下载文档
文本预览下载声明
截图代码 Posted on 2007-07-16 13:02 小y 阅读(6925) 评论(20) 编辑 收藏 可以利用Graphics类的CopyFromScreen方法来实现屏幕截取,舍弃了比较麻烦的API函数,只要几句代码就能实现了,而且这个这个方法能实现只抓取部分区域的屏幕,可以实现类似qq抓屏的功能。 using?System; using?System.Collections.Generic; using?System.Text; using?System.Drawing; using?System.Drawing.Imaging; using?System.Windows.Forms; namespace?ConsoleApplication1 ...{ ????class?Program ????...{ ????????static?void?Main(string[]?args) ????????...{ ??????????????? //获得当前屏幕的分辨率 ????????????Screen?scr?=?Screen.PrimaryScreen; ????????????Rectangle?rc?=?scr.Bounds; ????????????int?iWidth?=?rc.Width;?? ????????????int?iHeight?=?rc.Height; ??????????????? //创建一个和屏幕一样大的Bitmap ????????????Image?myImage?=?new?Bitmap(iWidth,?iHeight); ??????????????? //从一个继承自Image类的对象中创建Graphics对象 ????????????Graphics?g?=?Graphics.FromImage(myImage); ??????????????? //抓屏并拷贝到myimage里 ????????????g.CopyFromScreen(new?Point(0,?0),?new?Point(0,?0),?new?Size(iWidth,?iHeight)); ??????????????? //保存为文件 ????????????myImage.Save(@c:/1.jpeg); ????????} ????} } ? 以上内容转自lijgame的blog,在此对作者表示感谢! 原文地址:/lijgame/archive/2006/12/18/1447921.aspx 现在就文中的“实现QQ截屏”功能继续研究如下。 1、首先要实现在屏幕上画图,即:可以在屏幕上画出一个矩形框,双击该矩形框将截取矩形框内的屏幕。 目前在屏幕上画图的C#实现代码如下: [DllImport(User32.dll)] ????????public?extern?static?System.IntPtr?GetDC(System.IntPtr?hWnd);??? ????????private?void?button19_Click(object?sender,?EventArgs?e) ????????{ ????????????System.IntPtr???DesktopHandle???=???GetDC(System.IntPtr.Zero); ????????????Graphics?g?=?Graphics.FromHdc(DesktopHandle); ????????????g.DrawRectangle(new?Pen(Color.Red),new?Rectangle(10,10,100,100)); ????????} 需要用到可恶的API,实在不想用这种方法来实现! 2、研究出QQ屏幕上画图的真相 继续研究QQ截图的功能,发现当点击“截图”按钮之后,屏幕变成静止的了,原先网页上跳动的东西都不动了,哈哈,原因很简单,QQ截取了整个屏幕,然后用这张静止的屏幕覆盖全屏,真是精妙的解决办法啊! ? 于是用C#实现是: 建一个子窗体ScreenForm ,在窗体上放一个pictureBox和一个label控件。ScreenForm代码如下: using?System; using?System.Collections.Generic; using?System.ComponentModel; using?System.Data; using?System.Drawing; using?System.Text; using?System.Windows.Forms; namespace?copyScreen { ????p
显示全部
相似文档