Accessing Individual Pixels From A HBITMAP

Posted on 2001-07-15
Last Modified: 2013-11-20

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.


Question by:RichJackson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 6284380
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

Expert Comment

ID: 6289588
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.

Author Comment

ID: 6289971
Hmmm, I am interested in the speed.  What's my other options.

Accepted Solution

MichaelS earned 35 total points
ID: 6290029
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 84
dog bark java program 15 130
sum28 challenge 31 117
no14 challenge 14 76
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question