Solved

Accessing Individual Pixels From A HBITMAP

Posted on 2001-07-15
4
880 Views
Last Modified: 2013-11-20
Hi

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.

Cheers

Rich
0
Comment
Question by:RichJackson
  • 2
4 Comments
 
LVL 5

Expert Comment

by:FengYuan
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
0
 
LVL 6

Expert Comment

by:MichaelS
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.
0
 

Author Comment

by:RichJackson
ID: 6289971
Hmmm, I am interested in the speed.  What's my other options.
0
 
LVL 6

Accepted Solution

by:
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
http://www.codeguru.com/bitmap/rotate_bitmap.shtml

and actually at
http://www.codeguru.com/bitmap
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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