?
Solved

Bitmap files

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

Expert Comment

by:nietod
ID: 1164680
In what language?
0
 
LVL 22

Expert Comment

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

Accepted Solution

by:
nietod earned 200 total points
ID: 1164682
answer coming.
0
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!

 
LVL 22

Expert Comment

by:nietod
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.  

continues.
0
 
LVL 22

Expert Comment

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

HDC DCHnd = CreateDC("DISPLAY",NULL,NULL,NULL);
HDC DCMem = CreateCompativleDC(DCHnd);

DeleteDC(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);

DeleteDC(DCMem);

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

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

764 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