2013-01-22 56 views
0

我使用的工具称为辛巴其中有Pascal的图书馆,我用的是函数调用,像这样使用:如何从屏幕创建图像并在屏幕上找到它们?

bitmapfromscreen(x, y, x', y') : integer 
findbitmapin(bmp, x, y, x', y') : boolean 

我开始学习C#,但我找不到找到类似的功能,为Visual C# (有getpixel这个函数,但我无法生成任何有用的东西)我看了一些采用类似过程的例子,但它们是我不能理清的相当复杂的程序。如果有办法做这些工作,你能告诉,展示或提供链接吗?

回答

0

我已经在互联网上找到的代码如下所示:

public Bitmap PrintScreen() 
    { 
     Rectangle rect = new Rectangle(Cursor.Position.X, Cursor.Position.Y, 500, 360);//Screen.PrimaryScreen.Bounds; 
     int color = Screen.PrimaryScreen.BitsPerPixel; 
     PixelFormat pFormat; 
     switch (color) 
     { 
      case 8: 
      case 16: 
       pFormat = PixelFormat.Format16bppRgb565; 
       break; 

      case 24: 
       pFormat = PixelFormat.Format24bppRgb; 
       break; 

      case 32: 
       pFormat = PixelFormat.Format32bppArgb; 
       break; 

      default: 
       pFormat = PixelFormat.Format32bppArgb; 
       break; 
     } 
     Bitmap bmp = new Bitmap(rect.Width, rect.Height, pFormat); 
     Graphics g = Graphics.FromImage(bmp); 
     g.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size); 
     return bmp; 
    } 

然后在你的代码,你可以这样做:

Bitmap screenImage = PrintScreen();