私はスクリーンショットを撮ることができるアプリケーションをコーディングしています.スクリーンショットを超高速(1秒に数回)取得してから処理する必要があります. これを行うために使用しているコードは次のとおりです。動作しますが、非常に遅いです。
using System.Drawing;
using System.Drawing.Imaging;
public static Bitmap CaptureScreen()
{
Bitmap BMP = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(BMP);
GFX.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y,
0, 0,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size,
System.Drawing.CopyPixelOperation.SourceCopy);
return BMP;
}
使用法 - :
Bitmap im1 = new Bitmap(CaptureScreen());
上記のコードは問題なく動作しますが、処理に少なくとも 5 秒かかります。したがって、誰かが上記のような方法を提供してください。より高速であることを除いて、画面全体ではなく、フォアグラウンド ウィンドウを使用してキャプチャしたいと考えています。
編集ここに比較コードがあります!
private void timer2_Tick(object sender, EventArgs e)
{
pictureBox1.Image = CaptureScreen();
pictureBox2.Image = CaptureScreenOld();
Bitmap im1 = (Bitmap)pictureBox1.Image;
Bitmap im2 = (Bitmap)pictureBox2.Image;
for (int y = 0; y < pictureBox1.Height; y++)
{
for (int x = 0; x < pictureBox1.Width; x++)
{
// Get the color of the current pixel in each bitmap
Color color1 = im1.GetPixel(x, y);
Color color2 = im2.GetPixel(x, y);
// Check if they're the same
if (color1 != color2)
{
// If not, generate a color...
Color myRed = Color.FromArgb(90, 0, 0);
// .. and set the pixel in one of the bitmaps
im2.SetPixel(x, y, myRed);
pictureBox2.Image = im2;
}
}
}
}