摘要:需调用API函数需在开头引入命名空间 using System.Runtime.InteropServices;获取当前窗口句柄:GetForegroundWindow()[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]public static extern IntPtr GetForegroundWindow();返回值类型是IntPtr,即为当前获得焦点窗口的句柄使用方法 : IntPtr myPtr=GetForegroundWindow();获取到该窗口句柄后,可以对该窗
阅读全文
摘要:截图后在picbox中显示,用定时器定时每毫秒截图一次,在picbox上显示就有动画效果.代码: [DllImport("user32.dll")] static extern bool GetCursorInfo(out CURSORINFO pci); private const Int32 CURSOR_SHOWING = 0x00000001; [StructLayout(LayoutKind.Sequential)] struct POINT { public Int32 x;...
阅读全文
摘要:使用方法如下: private void button1_Click(object sender, EventArgs e) { s.GerScreenFormRectangle(); } private Zgke.CopyScreen s; private void Form1_Load(object sender, EventArgs e) { s = new Zgke.CopyScreen(); s.GetScreenImage+=ne...
阅读全文
摘要:class HiPerTimer { [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); /// /// 最后一次输入的时间间隔,静态函数,不用实例化即可调用 /// /// 返回时间长度 public static long GetLastInputTime() { LASTINPUTINFO vLastInputInfo...
阅读全文
摘要:/// /// 将源图像灰度化,并转化为8位灰度图像。 /// /// 源图像。 /// 8位灰度图像。 public static Bitmap RgbToGrayScale(Bitmap original) { if (original != null) { // 将源图像内存区域锁定 Rectangle rect = new Rectangle(0, 0, original....
阅读全文
摘要:/// /// 复制屏幕到内存中 /// /// 返回内存流 public static MemoryStream GetScreenPng() { Screen sc = Screen.PrimaryScreen;//取得主屏 Rectangle rct = sc.Bounds;//得到主屏的范围 Image img = new Bitmap(rct.Width, rct.Height); Graphics gp =...
阅读全文
摘要:Image img = this.pictureBox1.Image;Bitmap map = new Bitmap(img);Image img = Bitmap;Image和Bitmap类概述GDI+的Image类封装了对BMP、GIF、JPEG、PNG、TIFF、WMF(Windows元文件)和EMF(增强WMF)图像文件的调入、格式转换以及简单处理的功能。而Bitmap是从Image类继承的一个图像类,它封装了Windows位图操作的常用功能。例如,Bitmap::SetPixel和Bitmap::GetPixel分别用来对位图进行读写像素操作,从而可以为图像的柔化和锐化处理提供一种可
阅读全文
摘要:Point ms = Control.MousePosition; //获取鼠标位置 this.label2.Text = string.Format("{0}:{1}", ms.X, ms.Y); MouseButtons mb= Control.MouseButtons; //获取鼠标按键 if (mb == System.Windows.Forms.MouseButtons.Left) this.label3.Text = "Left"; if (mb == System.W...
阅读全文