?
Solved

Reading pixel values using C++

Posted on 1997-10-14
2
Medium Priority
?
998 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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

777 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