programuje w C++ od niedawna, czytałem o tym sporo ale nie mogę zajarzyć :/
stworzyłem sobie program konsolowy który wyświetla aktualny RGB, nie wiem co zrobić aby pobierało tak jak GetPixel. Kod znalazłem na necie, żeby się później na nim odwzorować, wyświetla cały czas 0,0,0, wiem że nie przypisuje nic wartościom RGB przed cout ale się nie da(no ja nie umiem ;x). A ta pętla for nie jest w ogóle brana pod uwagę, ogólnie cały kod jest bez sensu (MAX_WIDTH * 4 * MAX_HEIGHT) - czy to jest do czegoś potrzebne?
#include <iostream>
#include <windows.h>
using namespace std;
HDC hdc, hdcTemp;
RECT rect;
BYTE* bitPointer;
int x, y;
int red, green, blue, alpha;
int main()
{
while(true)
{
hdc = GetDC(0);
GetWindowRect(0, &rect);
int MAX_WIDTH = rect.right;
int MAX_HEIGHT = rect.bottom;
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 = MAX_WIDTH * 4 * MAX_HEIGHT;
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);
cout << red << ", " << green << ", " << blue << endl;
for (int i=0; i<(MAX_WIDTH * 4 * MAX_HEIGHT); i+=4)
{
red = (int)bitPointer[i];
green = (int)bitPointer[i+1];
blue = (int)bitPointer[i+2];
alpha = (int)bitPointer[i+3];
x = i / (4 * MAX_HEIGHT);
y = i / (4 * MAX_WIDTH);
if (red == 255 && green == 0 && blue == 0)
{
/////////////
cout << "Czerwony" << endl;
}
}
}
}