Accessing Individual Pixels From A HBITMAP


I have a HBITMAP, for which i would like to be able access inidividual pixel's RGB values .

How do i go about this?

The bits per pixel for the bitmap, isn't known its loaded by the user.


Who is Participating?
MichaelSConnect With a Mentor Commented:
Than you have to go for GetDIBits() approach, you will get pointer to bitmap data itself. Than you have to analize which type of bitmap (actually DIB) are you diling with, colors, size and .... Than you can use direct pointers.

Take a look at

and actually at
1) Use GetDIBits to convert it to a DIB and then read the pixels
2) Select into a memory DC, and then use GetPixel to read
You can create a memory DC, select your bitmap to it and than use functions GetPixel() and SetPixel(). But if you interested in speed than you will be disappointed :( This approach is easy to do but quite slow.

HDC hdc = CreateCompatibleDC(NULL);
SelectObject(hdc, hBitmpa);
COLORREF cr = GetPixel(hdc, 10, 10);

this code will give you RGB value of pixel (10, 10) in your bitmap.
RichJacksonAuthor Commented:
Hmmm, I am interested in the speed.  What's my other options.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.