这是我放在一起的一些代码(我没有写所有这些)
Bitmap thisScreenshot = new Bitmap(Width, Height);
Graphics gfxScreenshot = Graphics.FromImage(thisScreenshot);
IntPtr hdcBitmap = gfxScreenshot.GetHdc();
PrintWindow(WindowToFind, hdcBitmap, 0);
gfxScreenshot.ReleaseHdc(hdcBitmap);
//until this is part its just getting image of window(thisScreenshot)
AForge.Imaging.Filters.ResizeBilinear filter = new AForge.Imaging.Filters.ResizeBilinear(100, 60);
Bitmap forthumbnail = filter.Apply(thisScreenshot);
pictureBox1.Image = forthumbnail;
//created thumbnail
//this is where it gets slightly interesting:
Choppa = new AForge.Imaging.Filters.Crop(new Rectangle(150,55,250,200));
Bitmap croppedACCEPTtext = Choppa.Apply(thisScreenshot);
string img1_ref, img2_ref;
Bitmap img1 = croppedACCEPTtext;
Bitmap img2 = Properties.Resources.txt305;
int count1 = 0, count2 = 0;
bool flag = true;
if (img1.Width == img2.Width && img1.Height == img2.Height)
{
for (int i = 0; i < img1.Width; i++)
{
for (int j = 0; j < img1.Height; j++)
{
img1_ref = img1.GetPixel(i, j).ToString();
img2_ref = img2.GetPixel(i, j).ToString();
if (img1_ref != img2_ref)
{
count2++;
flag = false;
break;
}
count1++;
}
}
if (count2 < 200)
{
//THIS IS WORKS, AND HAPPENS CORRECTLY.
//THIS IS WORKS, AND HAPPENS CORRECTLY.
}
else
{
}
}
else
{
}
//Now, remaining part above doesnt work.
//its always false, unless when I look for count2 <400, then its always true.
AForge.Imaging.Filters.Crop Choppah = new AForge.Imaging.Filters.Crop(new Rectangle(150, 55, 350, 300));
croppedACCEPTtext = Choppah.Apply(thisScreenshot);
img1 = croppedACCEPTtext;
count1 = 0;
count2 = 0;
flag = true;
img2 = Properties.Resources.txt306;
if (img1.Width == img2.Width && img1.Height == img2.Height)
{
for (int i = 0; i < img1.Width; i++)
{
for (int j = 0; j < img1.Height; j++)
{
img1_ref = img1.GetPixel(i, j).ToString();
img2_ref = img2.GetPixel(i, j).ToString();
if (img1_ref != img2_ref)
{
count2++;
flag = false;
break;
}
count1++;
}
}
if (count2 < 400)
{
//fail ?
}
else
{
}
}
else
{
}
这段代码不是我的,并且由于某种原因它们失败了。我似乎无法理解为什么。