資源簡介
C#Winfom程序,實現窗口實時截圖,輸入窗口名稱,實時抓取屏幕窗口,即使窗口沒有獲得焦點,或者不處于前端,甚至不可見(只要窗口不最小化)都可以抓取,并呈現在前段 ,用到了Win32API函數

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Runtime.InteropServices;
using?System.Threading;
using?System.Drawing.Imaging;
using?System.Diagnostics;
using?System.IO;
namespace?WindowsFormsApplication1
{
????public?partial?class?Form1?:?Form
????{
????????System.Timers.Timer?timer;
????????static?string?wintext?=?string.Empty;
????????bool?isStart?=?false;
????????public?Form1()
????????{
????????????InitializeComponent();
????????????wintext?=?textBox1.Text;
????????}
????????///?
????????///?窗口加載調用函數
????????///?
????????///?
????????///?
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
???????????timer1.Tick?+=new?EventHandler(timer1_Tick);
????????????timer1.Interval?=?1000;
????????????timer1.Enabled=false;
????????}
????????public??byte[]?ImageToBinary(string?imagePath)
????????{
????????????FileStream?fileStream?=?new?FileStream(imagePath?FileMode.Open?FileAccess.Read);
????????????byte[]?buffer?=?new?byte[fileStream.Length];
????????????fileStream.Read(buffer?0?(int)fileStream.Length);
????????????fileStream.Close();
????????????return?buffer;
????????}
????????///?
????????///?把圖片轉換成字節格式
????????///?
????????///?圖片名稱
????????///?
????????private?byte[]?ImageToByte(Image?image)???????
????????{???????????//Image?image?=(Image)?pb.Image.Clone();???????????????????
????????????//?pb.Image.Dispose();?????????????????????
????????????//byte[]?b?=?null;???????????
????????????try???????????
????????????{???????????????
????????????????Image?sceneImage?=?new?Bitmap(image);?????????????????
????????????????////實例化流???????????????
????????????????System.IO.MemoryStream?imageStream?=?new?System.IO.MemoryStream();???????????????
????????????????//將圖片的實例保存到流中???????????????
????????????????sceneImage.Save(imageStream?ImageFormat.Jpeg);???????????????
????????????????//保存流的二進制數組??????????????
????????????????byte[]?imageContent?=?new?Byte[imageStream.Length];???????????????
????????????????imageStream.Position?=?0;???????????????
????????????????//將流瀉如數組中???????????????
????????????????imageStream.Read(imageContent?0?(int)imageStream.Length);???????????????
????????????????return?imageStream.ToArray();???????????
????????????}???????????
????????????catch?(Exception?ex)???????????
????????????{????????????????throw;??????????
????????????}???????????//?return?b;??????
????????}
????????public?Image?BinaryToImage(byte[]?imgByte)
????????{
????????????if?(imgByte?==?null)?return?null;
????????????byte[]?buffer?=?imgByte.ToArray();
????????????MemoryStream?memStream?=?new?MemoryStream();
????????????memStream.Write(buffer?0?buffer.Length);
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????10240??2012-11-26?12:02??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
?????文件??????24064??2012-11-26?12:02??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
?????文件??????11600??2012-11-26?12:02??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
?????文件????????631??2012-11-27?12:22??WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\Capture.jpg
?????文件??????56320??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.exe
?????文件??????28160??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.pdb
?????文件??????11600??2012-12-25?14:51??WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe
?????文件????????490??2010-03-17?22:39??WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe.manifest
?????文件??????43752??2012-11-27?11:18??WindowsFormsApplication1\WindowsFormsApplication1\Capture.jpg
?????文件???????7445??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
?????文件???????3779??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
?????文件???????6011??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
?????文件???????5420??2012-11-26?10:23??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6374??2012-11-26?12:02??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????938??2012-11-26?12:02??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件????????975??2012-11-26?11:59??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
?????文件???????9174??2012-11-26?10:35??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csprojResolveAssemblyReference.cache
?????文件??????10240??2012-11-26?12:02??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
?????文件????????180??2012-11-26?11:59??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
?????文件??????24064??2012-11-26?12:02??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
?????文件????????180??2012-11-24?14:18??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
?????文件???????4440??2012-12-12?10:06??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\DesignTimeResolveAssemblyReferences.cache
?????文件???????6841??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1034??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\GenerateResource.read.1.tlog
?????文件???????1102??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\GenerateResource.write.1.tlog
?????文件???????4608??2012-11-27?11:24??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\TempPE\Properties.Resources.Designer.cs.dll
?????文件???????2437??2012-12-25?14:51??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件????????975??2012-11-26?11:59??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.csproj.GenerateResource.Cache
?????文件??????12765??2012-11-26?13:20??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.csprojResolveAssemblyReference.cache
?????文件??????56320??2012-12-25?14:48??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe
............此處省略30個文件信息
- 上一篇:C#仿360加速球
- 下一篇:C# 標準偏差STDEV與CPK的計算
評論
共有 條評論