资源简介
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的计算
评论
共有 条评论