Solved

Reading pixel values using C++

Posted on 1997-10-14
2
984 Views
Last Modified: 2008-03-03
I'am currently doing a project on data compression using C++. I need to open an image file and read the pixel values.  
Is there an equivalent of the getpixel command of C in C++?
Hope to hear from someone out there soon. Thanks in advance.
0
Comment
Question by:dnair
2 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1171334
an easy (though innefficient) method would be to create a memorydevice context and load it with the image.  then use getpixel.

Alternately, you can parse the image file if you know its format.  The windows bitmap formats are documented and not too hard to parse.  A Windows META file would be almost impossible to parse, specially in this context.  

I can provide more specifics on either technique.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 1171335
You can load an image from an external file with LoadImage (under win95 at least) - this creates a bitmap (or a DIB if you prefer).  Or you can directly read the image into a bitmap (lots of sample code around for this)

You can then either use GetPixel/SetPixel to access it pixel-by-pixel.

However, in your case, you would probably be better off with GetDIBits to get ALL the pixel data at once into a buffer that you can access any way you want.


0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

706 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

16 Experts available now in Live!

Get 1:1 Help Now