判断客户区中是否显示了已知位图,应该如何定义像素数组呀
判断客户区中是否显示了已知位图,应该怎么定义像素数组呀?
我的代码是这样写的
void CNbmpView::OnBtnFind()
{
Color cobitmap[170][179]; //定义位图像素数组
for (int x=0;x<=170-1;x++)
{
for (int y=0;y<=179-1;y++)
{
bitmap5->GetPixel(x,y,&cobitmap[x][y]);
}
} //获取位图像素数组
Color coclient[1020][669]; //定义客户区位图数组
Bitmap *bitmap6=::new Bitmap((HBITMAP)::GetCurrentObject(hActiveDC, OBJ_BITMAP),NULL);
bitmap5=::new Bitmap((HBITMAP)::GetCurrentObject(hActiveDC, OBJ_BITMAP),NULL);
for (int x=0;x<=1020-1;x++)
{
for (int y=0;y<=669-1;y++)
{
bitmap6->GetPixel(x,y,&coclient[x][y]);
}
} //获取客户区位图数组
for (int w=0;w<=1020-1-170;w++)
{
for (int h=0;h<=669-1-179;h++)
{
if (cobitmap[0][0].GetRed()==coclient[w][h].GetRed()&&
cobitmap[0][0].GetGreen()==coclient[w][h].GetGreen()&&
cobitmap[0][0].GetBlue()==coclient[w][h].GetBlue())
//判断客户区中和位图左上角像素相同的点
{
for (int x=0;x<=170-1;x++)
{
for (int y=0;y<=179-1;y++)
{
for (int a=w;a<=w+170;a++)
{
for(int b=h;b<=h+179;b++)
{ //判断其余点是否全相同
if (
(cobitmap[x][y].GetRed()!=coclient[a][b].GetRed()) |
(cobitmap[x][y].GetGreen()!=coclient[a][b].GetGreen()) |
(cobitmap[x][y].GetBlue()!=coclient[a][b].GetBlue()))
{
goto Label_1; //有不同的点跳出
}
}
}
CString str;
str.Format(TEXT("按钮在(%d,%d)"),w,h);
MessageBox(str); //有完全相同,独处坐标并返回
return;
}
}
}
Label_1:; //跳出继续判断下一个和位图左上角像素相同的点
}
}
}
编译可以通过,但是调试的时候,运行到这里就出异常,
chksstk.asm
cs20:
sub eax, _PAGESIZE_ ; decrease by PAGESIZE
test dword ptr [eax],eax ; probe page. //编译器提示运行到这里出现异常
jmp short cs10
------解决方案--------------------
你用了goto?!!
这个习惯不太好
单步调试一下
具体定位问题点
------解决方案--------------------
是否数组处理越界
我的代码是这样写的
void CNbmpView::OnBtnFind()
{
Color cobitmap[170][179]; //定义位图像素数组
for (int x=0;x<=170-1;x++)
{
for (int y=0;y<=179-1;y++)
{
bitmap5->GetPixel(x,y,&cobitmap[x][y]);
}
} //获取位图像素数组
Color coclient[1020][669]; //定义客户区位图数组
Bitmap *bitmap6=::new Bitmap((HBITMAP)::GetCurrentObject(hActiveDC, OBJ_BITMAP),NULL);
bitmap5=::new Bitmap((HBITMAP)::GetCurrentObject(hActiveDC, OBJ_BITMAP),NULL);
for (int x=0;x<=1020-1;x++)
{
for (int y=0;y<=669-1;y++)
{
bitmap6->GetPixel(x,y,&coclient[x][y]);
}
} //获取客户区位图数组
for (int w=0;w<=1020-1-170;w++)
{
for (int h=0;h<=669-1-179;h++)
{
if (cobitmap[0][0].GetRed()==coclient[w][h].GetRed()&&
cobitmap[0][0].GetGreen()==coclient[w][h].GetGreen()&&
cobitmap[0][0].GetBlue()==coclient[w][h].GetBlue())
//判断客户区中和位图左上角像素相同的点
{
for (int x=0;x<=170-1;x++)
{
for (int y=0;y<=179-1;y++)
{
for (int a=w;a<=w+170;a++)
{
for(int b=h;b<=h+179;b++)
{ //判断其余点是否全相同
if (
(cobitmap[x][y].GetRed()!=coclient[a][b].GetRed()) |
(cobitmap[x][y].GetGreen()!=coclient[a][b].GetGreen()) |
(cobitmap[x][y].GetBlue()!=coclient[a][b].GetBlue()))
{
goto Label_1; //有不同的点跳出
}
}
}
CString str;
str.Format(TEXT("按钮在(%d,%d)"),w,h);
MessageBox(str); //有完全相同,独处坐标并返回
return;
}
}
}
Label_1:; //跳出继续判断下一个和位图左上角像素相同的点
}
}
}
编译可以通过,但是调试的时候,运行到这里就出异常,
chksstk.asm
cs20:
sub eax, _PAGESIZE_ ; decrease by PAGESIZE
test dword ptr [eax],eax ; probe page. //编译器提示运行到这里出现异常
jmp short cs10
------解决方案--------------------
你用了goto?!!
这个习惯不太好
单步调试一下
具体定位问题点
------解决方案--------------------
是否数组处理越界