2013-01-22 51 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();