Solved

Reading pixel values using C++

Posted on 1997-10-14
2
993 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
[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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

756 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