Solved

Reading pixel values using C++

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

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!

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…
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…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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