Image myImage = new Bitmap(300, 200);
Graphics g = Graphics.FromImage(myImage);
g.CopyFromScreen(new Point(Cursor.Position.X - 150, Cursor.Position.Y - 25), new Point(0, 0), new Size(300, 200));
IntPtr dc1 = g.GetHdc();
g.ReleaseHdc(dc1);
this.pictureBox1.Image = myImage;
myImage.Save("c://1.jpeg");
抓图 需要的DLL
using System.Drawing;
using System.Drawing.Imaging;
//再经过8句将位图变换成整形数组矩阵。可以最大限度的提高图像处理速度。
比 myBitmap.GetPixel(???)方法快100倍以上速度与C++指针操作不相上下。
//获得图像
Rectangle rec = new Rectangle(0, 0, myBitmap.Width, myBitmap.Height);
BitmapData bmpData = myBitmap.LockBitsrec,ImageLockMode.ReadWrite,PixelFormat.Format32bppPArgb);
//将图像变换
IntPtr scan0 = bmpData.Scan0;
int len = myBitmap.Width * myBitmap.Height;
int[] pixels = new int[len];
Marshal.Copy(scan0, pixels, 0, len);
myBitmap.UnlockBits(bmpData);
myBitmap.Dispose();
DelegateShowLabelstr dc1 = new DelegateShowLabelstr(ShowLabelstr);
DelegateShowLabelstrgz("处理完成", dc1); //回调其他线程