Hi everyone!
Getpixel() is too slow so I am trying to use bitmap to load the RGB values into a pointer to access the RGB values rapidly, but it seems
either I messed up on the bitmap operations or I can't get the pointer right!
I use Pixelcolor() to compare so I know I have it right if the returned RGB values matches one another.
Can anyone help me out?
thx!
Code:
#include <iostream>
#include <Windows.h>
using namespace std;
void cout_colour();
void get_pixel();
void main()
{
cout_colour();
get_pixel();
}
void cout_colour()
{
HDC hdc, hdcTemp;
RECT rect;
BYTE* bitPointer;
int red = 0;
int green = 0;
int blue = 0;
hdc = GetDC(GetDesktopWindow());
GetWindowRect(GetDesktopWindow(), &rect);
int MAX_WIDTH = rect.right;
int MAX_HEIGHT = rect.bottom;
cout << "MAX_WIDTH" << MAX_WIDTH << endl;
cout << "MAX_HEIGHT" << MAX_HEIGHT << endl;
hdcTemp = CreateCompatibleDC(hdc);
BITMAPINFO bitmap;
bitmap.bmiHeader.biSize = sizeof(bitmap.bmiHeader);
bitmap.bmiHeader.biWidth = MAX_WIDTH;
bitmap.bmiHeader.biHeight = MAX_HEIGHT;
bitmap.bmiHeader.biPlanes = 1;
bitmap.bmiHeader.biBitCount = 32;
bitmap.bmiHeader.biCompression = BI_RGB;
bitmap.bmiHeader.biSizeImage = 0;
bitmap.bmiHeader.biClrUsed = 0;
bitmap.bmiHeader.biClrImportant = 0;
HBITMAP hBitmap2 = CreateDIBSection(hdcTemp, &bitmap, DIB_RGB_COLORS, (void**)(&bitPointer), NULL, NULL);
SelectObject(hdcTemp, hBitmap2);
BitBlt(hdcTemp, 0, 0, MAX_WIDTH, MAX_HEIGHT, hdc, 0, 0, SRCCOPY);
int i = 1;
int x = 1;
int y = 1;
SetCursorPos(x, y);
red = (int)bitPointer[i];
green = (int)bitPointer[i + 1];
blue = (int)bitPointer[i + 2];
cout << red << " " << green << " " << blue << endl;
DeleteDC(hdc);
}
void get_pixel()
{
int x = 1;
int y = 1;
COLORREF hex_color;
int red;
int green;
int blue;
HDC dc = GetDC(GetDesktopWindow());
hex_color = GetPixel(dc, x, y);
red = GetRValue(hex_color);
green = GetGValue(hex_color);
blue = GetBValue(hex_color);
cout << "Super Slow RGB cout!" << endl;
cout << red << " " << green << " " << blue << endl;
}