level 8
Sail丶Man
楼主
这次仅仅去掉了saveimage(_T("f:\\testq1.bmp"), &img);loadimage(&img, "f:\\testq1.bmp");程序就识别不了这个img 就找不到色 ,就是 按Y 后 没反应了。
——————————————————————————
# include <graphics.h>
# include <stdio.h>
int start(void);
void Quit(void);
void CaptureDesktop(IMAGE *pimg)
{int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
Resize(pimg, w, h);HDC aa = GetDC(NULL);
HDC dstDC = GetImageHDC(pimg);
BitBlt(dstDC, 0, 0, w, h, aa, 0, 0, SRCCOPY);}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{COLORREF cr;cr = start();
initgraph(200,60);
TCHAR s2[20];
sprintf(s2, _T("%#x"), cr);
TCHAR s1[30]="已确定你要找的颜色值为:";
outtextxy(0, 0, s1);
outtextxy(0, 20, s2);
TCHAR s[30]="按Y键开始找色,按B键退出";
outtextxy(0, 40, s);
int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
while (true){if (GetAsyncKeyState('Y'))
{closegraph();break;}Quit();}
while (true)
{IMAGE img;
CaptureDesktop(&img);
/*initgraph(640, 480);putimage(0, 0, &img);*/
DWORD* p = GetImageBuffer(&img);
POINT point;for(int i = 0; i < w * h; i++)
if (p[i] == BGR(cr) ){point.y = i / (w * 1.0);
point.x = i - point.y * w ;Sleep(100);
SetCursorPos(point.x, point.y);break;}
DeleteFile("f:\\testq1.bmp");Quit();}return 0;}
int start(void){initgraph(150,80);
HDC hdc = GetDC(NULL);COLORREF cr;
POINT point;TCHAR s[20];TCHAR s1[20]="横坐标:";TCHAR s2[20]="纵坐标:";
TCHAR s3[20]="颜色值:";
TCHAR s4[30]="按A键确定,按B键退出";
while(true){GetCursorPos(&point);
sprintf(s, _T("%05d"), point.x);
outtextxy(0, 0, s1);outtextxy(55, 0, s);
sprintf(s, _T("%05d"), point.y);outtextxy(0, 20, s2);
outtextxy(55, 20, s);Sleep(10);
cr = GetPixel(hdc, point.x, point.y);
sprintf(s, _T("%#x"), cr);outtextxy(0, 40, s3);
outtextxy(55, 40, s);outtextxy(0, 60, s4);
if (GetAsyncKeyState('A')){closegraph();ReleaseDC(NULL,hdc);return cr;}Quit();}}
void Quit(void){if(GetAsyncKeyState('B'))
{if(MessageBox(NULL, "你确定要退出吗?","提示", MB_YESNO) == IDYES)
exit(0);}return ;}
2013年09月27日 00点09分
1
——————————————————————————
# include <graphics.h>
# include <stdio.h>
int start(void);
void Quit(void);
void CaptureDesktop(IMAGE *pimg)
{int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
Resize(pimg, w, h);HDC aa = GetDC(NULL);
HDC dstDC = GetImageHDC(pimg);
BitBlt(dstDC, 0, 0, w, h, aa, 0, 0, SRCCOPY);}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{COLORREF cr;cr = start();
initgraph(200,60);
TCHAR s2[20];
sprintf(s2, _T("%#x"), cr);
TCHAR s1[30]="已确定你要找的颜色值为:";
outtextxy(0, 0, s1);
outtextxy(0, 20, s2);
TCHAR s[30]="按Y键开始找色,按B键退出";
outtextxy(0, 40, s);
int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
while (true){if (GetAsyncKeyState('Y'))
{closegraph();break;}Quit();}
while (true)
{IMAGE img;
CaptureDesktop(&img);
/*initgraph(640, 480);putimage(0, 0, &img);*/
DWORD* p = GetImageBuffer(&img);
POINT point;for(int i = 0; i < w * h; i++)
if (p[i] == BGR(cr) ){point.y = i / (w * 1.0);
point.x = i - point.y * w ;Sleep(100);
SetCursorPos(point.x, point.y);break;}
DeleteFile("f:\\testq1.bmp");Quit();}return 0;}
int start(void){initgraph(150,80);
HDC hdc = GetDC(NULL);COLORREF cr;
POINT point;TCHAR s[20];TCHAR s1[20]="横坐标:";TCHAR s2[20]="纵坐标:";
TCHAR s3[20]="颜色值:";
TCHAR s4[30]="按A键确定,按B键退出";
while(true){GetCursorPos(&point);
sprintf(s, _T("%05d"), point.x);
outtextxy(0, 0, s1);outtextxy(55, 0, s);
sprintf(s, _T("%05d"), point.y);outtextxy(0, 20, s2);
outtextxy(55, 20, s);Sleep(10);
cr = GetPixel(hdc, point.x, point.y);
sprintf(s, _T("%#x"), cr);outtextxy(0, 40, s3);
outtextxy(55, 40, s);outtextxy(0, 60, s4);
if (GetAsyncKeyState('A')){closegraph();ReleaseDC(NULL,hdc);return cr;}Quit();}}
void Quit(void){if(GetAsyncKeyState('B'))
{if(MessageBox(NULL, "你确定要退出吗?","提示", MB_YESNO) == IDYES)
exit(0);}return ;}