Главная страница | назад





Article #16629: Bitmap RGB values

 Question and Answer Database

FAQ1629C.txt   Bitmap RGB values
Category   :Windows API
Platform    :All
Product    :BC++  5.x

Question:

I need to be able to load bmps and get at the rgb values at any
given point within them. As anyone got some SIMPLE example code,
or knows where I can get hold of some.

Answer:

HBITMAP hBitmap;
HDC hMemDC, hdc; ; // for bitmaps
COLORREF PixColor;
char Buffer1[200] = "Test_1.bmp";

hdc = GetDC(hwnd);
hMemDC = CreateCompatibleDC(hdc); // memory dc for bitmaps


hBitmap = LoadImage(NULL,Buffer1, 
IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);

SelectObject(hMemDC,hBitmap);
// Draw to visible window if you wish
// BitBlt(hdc,0,0,640,WindowHeight,hMemDC,0,0,MERGECOPY);

PixColor = GetPixel(hdc, x , y ); 

7/2/98 10:32:32 AM
 

Last Modified: 01-SEP-99