Bitmap files

Posted on 1998-05-24
Last Modified: 2012-05-04
How can i read each pixel of a Bitmap file, please give me some code?
Question by:bolso
  • 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 100 total points
ID: 1164682
answer coming.
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now