|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
现在做一个保存屏幕某窗口截图后,分析图中图像的功能(连连看),
遇到了GetDIBits的使用问题,
代码一点点,前面经过一定的验证应该是对的啦,
hbitmap中的图像也保存过粘贴板再保存下来,现在想进行一个像素一个像素的分析。
- #include <windows.h>
- #include <Winuser.h>
- #include <iostream>
- #include "stdio.h"
- using namespace std;
- #define appwidth 800
- #define appheight 600
- int main()
- {
- //控制台窗口位置改变
- HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 获取标准输出设备句柄
- CONSOLE_SCREEN_BUFFER_INFO bInfo; // 窗口缓冲区信息
- GetConsoleScreenBufferInfo(hOut, &bInfo );// 获取窗口缓冲区信息
- SMALL_RECT rc = {10,10, 40-1, 25-1};// 重置窗口位置和大小
- SetConsoleWindowInfo(hOut,true ,&rc);
- getchar();
- HWND hwnd = NULL;//全局主窗口句柄
- HWND hwndapp = FindWindow(0, "QQ游戏 - 连连看角色版");// 目标窗口句柄
- RECT parentrect;// 目标窗体方框
- HDC screendc = NULL;//屏幕DC
- HDC cutdc = NULL;//截图DC
- HBITMAP hbitmap = NULL; //待传入的图
- //把窗口图像保存
- GetWindowRect(hwndapp, &parentrect);
- screendc = GetDC(NULL);
- cutdc = CreateCompatibleDC(screendc);
- hbitmap = CreateCompatibleBitmap(screendc,appwidth,appheight);//游戏窗口为定值不变
- SelectObject(cutdc,hbitmap);
- BitBlt(cutdc,0,0,appwidth,appheight,screendc,parentrect.left,parentrect.top,SRCCOPY);
- //应该是从这里开始错的。。。。。。先进行第五个参数为NULL的,返回值为0,GETLASTERROR也是0
- BITMAPINFO bitmapinfo;
- bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- GetDIBits(cutdc,hbitmap,0,10,NULL,&bitmapinfo,DIB_RGB_COLORS);
- cout<<bitmapinfo.bmiHeader.biBitCount<<' '
- <<bitmapinfo.bmiHeader.biHeight<<' '
- <<bitmapinfo.bmiHeader.biPlanes<<' '
- <<bitmapinfo.bmiHeader.biBitCount<<' '
- <<bitmapinfo.bmiHeader.biWidth<<' ';
- //这是第五个参数不为NULL的还没用
- // unsigned char *bitmap_use = new unsigned char[bitmapinfo.bmiHeader.biSizeImage];
- // memset(bitmap_use, 0, bitmapinfo.bmiHeader.biSizeImage);
- // cout<<GetDIBits(cutdc, hbitmap, 0, appheight, bitmap_use, &bitmapinfo, DIB_RGB_COLORS)<<endl;
- DeleteObject(hbitmap);
- DeleteDC(cutdc);
- cout<<"done!"<<endl;
- return 0;
- }
复制代码
不要说用CE查内存得到棋盘什么的,请帮我解决这个函数使用吧,非常感谢! |
|