一个抓取电脑屏幕的小控件台程序
生活随笔
收集整理的這篇文章主要介紹了
一个抓取电脑屏幕的小控件台程序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一個抓取電腦屏幕的小控件臺程序
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing;
using?System.Drawing.Imaging;
namespace?DeskRegistrar
{
????class?Program
????{
????????//聲明一個API函數(shù)
????????[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
????????private?static?extern?bool?BitBlt(
?????????????IntPtr?hdcDest,?//?目標?DC的句柄
?????????????int?nXDest,
?????????????int?nYDest,
?????????????int?nWidth,
?????????????int?nHeight,
?????????????IntPtr?hdcSrc,??//?源DC的句柄
?????????????int?nXSrc,
?????????????int?nYSrc,
?????????????System.Int32?dwRop??//?光柵的處理數(shù)值
?????????????);
????????[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
????????private?static?extern?IntPtr?CreateDC(
????????????string?lpszDriver,???//???驅動名稱???
????????????string?lpszDevice,???//???設備名稱???
????????????string?lpszOutput,???//???無用,可以設定位"NULL"???
????????????IntPtr?lpInitData????//???任意的打印機數(shù)據(jù)???
????????????);
????????static?void?Main(string[]?args)
????????{
????????????System.Threading.Timer?timer?=?new?System.Threading.Timer(delegate(Object?o)
????????????{
????????????????IntPtr?dc1?=?CreateDC("DISPLAY",?null,?null,?(IntPtr)null);
????????????????//創(chuàng)建顯示器的DC???
????????????????Graphics?g1?=?Graphics.FromHdc(dc1);
????????????????//由一個指定設備的句柄創(chuàng)建一個新的Graphics對象???
????????????????Image?MyImage?=?new?Bitmap(Screen.PrimaryScreen.Bounds.Width,?Screen.PrimaryScreen.Bounds.Height,?g1);
????????????????//根據(jù)屏幕大小創(chuàng)建一個與之相同大小的Bitmap對象???
????????????????Graphics?g2?=?Graphics.FromImage(MyImage);
????????????????//獲得屏幕的句柄???
????????????????IntPtr?dc3?=?g1.GetHdc();
????????????????//獲得位圖的句柄???
????????????????IntPtr?dc2?=?g2.GetHdc();
????????????????//把當前屏幕捕獲到位圖對象中???
????????????????BitBlt(dc2,?0,?0,?Screen.PrimaryScreen.Bounds.Width,?Screen.PrimaryScreen.Bounds.Height,?dc3,?0,?0,?13369376);
????????????????//把當前屏幕拷貝到位圖中???
????????????????g1.ReleaseHdc(dc3);
????????????????//釋放屏幕句柄???
????????????????g2.ReleaseHdc(dc2);
????????????????//釋放位圖句柄???
????????????????MyImage.Save(AppDomain.CurrentDomain.BaseDirectory?+?"\\"?+?DateTime.Now.ToString("yyyyMMddHHmmss")?+?".jpg",?ImageFormat.Jpeg);
????????????????//MessageBox.Show("已經(jīng)把當前屏幕保存到C:\\MyJpeg.jpg文件中!");?
????????????},?null,?0,?3000);
????????????Console.Read();
????????}
????}
}
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing;
using?System.Drawing.Imaging;
namespace?DeskRegistrar
{
????class?Program
????{
????????//聲明一個API函數(shù)
????????[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
????????private?static?extern?bool?BitBlt(
?????????????IntPtr?hdcDest,?//?目標?DC的句柄
?????????????int?nXDest,
?????????????int?nYDest,
?????????????int?nWidth,
?????????????int?nHeight,
?????????????IntPtr?hdcSrc,??//?源DC的句柄
?????????????int?nXSrc,
?????????????int?nYSrc,
?????????????System.Int32?dwRop??//?光柵的處理數(shù)值
?????????????);
????????[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
????????private?static?extern?IntPtr?CreateDC(
????????????string?lpszDriver,???//???驅動名稱???
????????????string?lpszDevice,???//???設備名稱???
????????????string?lpszOutput,???//???無用,可以設定位"NULL"???
????????????IntPtr?lpInitData????//???任意的打印機數(shù)據(jù)???
????????????);
????????static?void?Main(string[]?args)
????????{
????????????System.Threading.Timer?timer?=?new?System.Threading.Timer(delegate(Object?o)
????????????{
????????????????IntPtr?dc1?=?CreateDC("DISPLAY",?null,?null,?(IntPtr)null);
????????????????//創(chuàng)建顯示器的DC???
????????????????Graphics?g1?=?Graphics.FromHdc(dc1);
????????????????//由一個指定設備的句柄創(chuàng)建一個新的Graphics對象???
????????????????Image?MyImage?=?new?Bitmap(Screen.PrimaryScreen.Bounds.Width,?Screen.PrimaryScreen.Bounds.Height,?g1);
????????????????//根據(jù)屏幕大小創(chuàng)建一個與之相同大小的Bitmap對象???
????????????????Graphics?g2?=?Graphics.FromImage(MyImage);
????????????????//獲得屏幕的句柄???
????????????????IntPtr?dc3?=?g1.GetHdc();
????????????????//獲得位圖的句柄???
????????????????IntPtr?dc2?=?g2.GetHdc();
????????????????//把當前屏幕捕獲到位圖對象中???
????????????????BitBlt(dc2,?0,?0,?Screen.PrimaryScreen.Bounds.Width,?Screen.PrimaryScreen.Bounds.Height,?dc3,?0,?0,?13369376);
????????????????//把當前屏幕拷貝到位圖中???
????????????????g1.ReleaseHdc(dc3);
????????????????//釋放屏幕句柄???
????????????????g2.ReleaseHdc(dc2);
????????????????//釋放位圖句柄???
????????????????MyImage.Save(AppDomain.CurrentDomain.BaseDirectory?+?"\\"?+?DateTime.Now.ToString("yyyyMMddHHmmss")?+?".jpg",?ImageFormat.Jpeg);
????????????????//MessageBox.Show("已經(jīng)把當前屏幕保存到C:\\MyJpeg.jpg文件中!");?
????????????},?null,?0,?3000);
????????????Console.Read();
????????}
????}
}
轉載于:https://www.cnblogs.com/gleamy_ming/archive/2009/03/20/1418067.html
總結
以上是生活随笔為你收集整理的一个抓取电脑屏幕的小控件台程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .Net面试题(3)
- 下一篇: 业务员的通病!