Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Bitmap files

Posted on 1998-05-24
Medium Priority
Last Modified: 2012-05-04
How can i read each pixel of a Bitmap file, please give me some code?
Question by:bolso
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
  • 6
LVL 22

Expert Comment

ID: 1164680
In what language?
LVL 22

Expert Comment

ID: 1164681
Probably C++, right?  (I'm not totally stupid.  I thought this was the window section.)
LVL 22

Accepted Solution

nietod earned 200 total points
ID: 1164682
answer coming.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 22

Expert Comment

ID: 1164683
What I would do is load the bitmap from the file using LoadImage().  Then you don't have to "parse" the information in the file  (which can be done if you are interested in doing it that way.)

To load the image you would do.

HBITMAP ImgHnd = LoadImage(NULL,"c:\path\filename.bmp",IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE);

This loads the image as a screen compatible bitmap.  I'm assuming that is what you want.  If you don't want it screen compatible it can be used to load a DIB bitmap.  

LVL 22

Expert Comment

ID: 1164684
To read the pixels, you need to select the bitmap into a compatible device context.  To do that you would do

HDC DCMem = CreateCompativleDC(DCHnd);


HBITMAP OldBitMap = SelectObject(DCMem,ImgHnd);// Select in image loaded from LoadImage().

// now use GetPixel() to get the pixels, like
COLOREF Color = GetPixel(DCMem,1,1);


I hope this helps.  Ask if you have questions.
LVL 22

Expert Comment

ID: 1164685
I have to go, but If you want to quickly get the pixel information in an array.  You can load the image as a DIB bitmap by specifying LR_CREATEDIBSECTION in the LoadImage() and then use GetDIBits() to get all the pixels at once.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

618 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