c/c++ 将 RGBQUAD 数组分配给位图 [英] c/c++ assign RGBQUAD array to a bitmap

查看:56
本文介绍了c/c++ 将 RGBQUAD 数组分配给位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个程序,您可以截取窗口的屏幕截图,然后扫描该图片的每个像素.但是我在将 RGBQUAD 数组分配给拍摄的屏幕时遇到了问题.每个像素都有相同的 RGB,即 205.这是我的一段代码:

i am doing a program where you take a screenshot of a window and then scan every pixel of that picture. But I have a problem assigning RGBQUAD array to the taken screen. Every pixel has the same RGB which is 205. Here is a piece of my code:

RGBQUAD *pixel = malloc((ssWidth * ssHeight)* sizeof(RGBQUAD));
hdcScreen = GetDC(gameHandle);
hdc = CreateCompatibleDC(hdcScreen);
hBmp = CreateCompatibleBitmap(hdcScreen, ssWidth, ssHeight);
SelectObject(hdc, hBmp);

BitBlt(hdc, 0, 0, ssWidth, ssHeight, hdcScreen, xCenter, yCenter, SRCCOPY);

GetDIBits(hdc, hBmp, 0, ssHeight, pixel, &bmpInfo, DIB_RGB_COLORS);

int p = -1;

for(y_var = 0; y_var < ssWidth; y_var++)
{
    for(x_var = 0; x_var < ssHeight; x_var++)
    {
        if(ComparePixel(&pixel[++p]))
        {
            SetCursorPos(xCenter + x_var + 3, yCenter + y_var + 3);
        }
    }
}

bool ComparePixel(RGBQUAD *pixel)
{
    printf("%d, %d, %d\n"; pixel -> rgbRed, pixel -> rgbGreen, pixel -> rgbBlue);
    return false;
}

ComparePixel(RGBQUAD *pixel) 函数只检查 RGB 值.如何将 RGBQUAD 分配给屏幕截图的位图?

ComparePixel(RGBQUAD *pixel) function just checks the RGB values. How do i assign the RGBQUAD to the bitmap of the screenshot?

推荐答案

多个问题.

  1. RGBQUAD **pixel = malloc(...free(*pixel) 似乎是问题所在.我想你想要 RGBQUAD *pixel = malloc((ssWidth * ssHeight)* sizeof(RGBQUAD));(只有1个*)

  1. The RGBQUAD **pixel = malloc(... and free(*pixel) appear to be the problem. I think you want RGBQUAD *pixel = malloc((ssWidth * ssHeight)* sizeof(RGBQUAD)); (only 1 *)

怀疑 GetDIBits() s/b pixel 中的 pixels.

Suspect the pixels in GetDIBits() s/b pixel.

我想你想要 y_var = 0; (x_var = 0; also)

I think you want y_var = 0; (x_var = 0; also)

ComparePixel() 未定义,但我认为您想要更接近于 if(ComparePixel(pixel[x_var+(y_var*ssWidth)], the_pixel_to_compare_against))

ComparePixel() is not defined, but I think you want something closer to if(ComparePixel(pixel[x_var+(y_var*ssWidth)], the_pixel_to_compare_against))

free(*pixel); s/b _after 2 for 循环,应该是 free(pixel);

The free(*pixel); s/b _after the 2 for loops and should be free(pixel);

这篇关于c/c++ 将 RGBQUAD 数组分配给位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆