2010-12-31 16 views
0

画面のセクションのスクリーンショットを撮り、その情報をイメージアレイに保存したいと考えています。このクラスを変更する方法はありますか: http://pastebin.com/PDPPxmPT 特定の領域のスクリーンショットを撮ることができるようになりますか?たとえば、ビットマップのx、yピクセルの起点を200,200、およびx、yの送り先を600,700にしたい場合は、どうすればよいでしょうか?C#の画面の特定のセクションのスクリーンショットを撮る?

+0

コードは、ペーストビンではなくご質問にご記入ください。 –

答えて

2

は、私はそれがhere

EDITを国防省:それはおそらく将来的にいつか消えるだろうと他人のために有用である可能性があるとして、ここでは、コード

public static Color[,] takeScreenshot(int x=0, int y=0, int width=0, int height = 0) 
     { 
    if (width==0) 
     width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; 
    if (height==0) 
     height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; 
      Bitmap screenShotBMP = new Bitmap(width, 
       height, PixelFormat.Format32bppArgb); 

      Graphics screenShotGraphics = Graphics.FromImage(screenShotBMP); 

      screenShotGraphics.CopyFromScreen(x, 
       y, 0, 0, new Size(width,height), 
       CopyPixelOperation.SourceCopy); 

      screenShotGraphics.Dispose(); 

      return bitmap2imagearray(screenShotBMP); 
     } 

public static Color[,] bitmap2imagearray(Bitmap b) 
     { 
      Color[,] imgArray = new Color[b.Width, b.Height]; 
      for (int y = 0; y < b.Height; y++) 
      { 
       for (int x = 0; x < b.Width; x++) 
       { 
        imgArray[x, y] = b.GetPixel(x, y); 
       } 
      } 
      return imgArray; 
     } 
+0

Pastebinではなく、あなたの答えにコードを載せてください。 –

0

ない答えだが、ペーストビンからコードを含みます。

public static Color[,] takeScreenshot() 
    { 
     Bitmap screenShotBMP = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, 
      System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); 

     Graphics screenShotGraphics = Graphics.FromImage(screenShotBMP); 

     screenShotGraphics.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X, 
      System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size, 
      CopyPixelOperation.SourceCopy); 

     screenShotGraphics.Dispose(); 

     return bitmap2imagearray(screenShotBMP); 
    } 

    public static Color[,] bitmap2imagearray(Bitmap b) 
    { 
     Color[,] imgArray = new Color[b.Width, b.Height]; 
     for (int y = 0; y < b.Height; y++) 
     { 
      for (int x = 0; x < b.Width; x++) 
      { 
       imgArray[x, y] = b.GetPixel(x, y); 
      } 
     } 
     return imgArray; 
    } 
関連する問題