Sign in to follow this  
MasterModakai

Displaying .img graphic file via Win32/MFC

Recommended Posts

MasterModakai    122
Ok.... I would like to add some functionality to a project I am working that will save me from pulling hair from my head (I'd rather not help that balding process, if you know what I mean). I have an application that performs various image processing tasks on a user supplied image file. As is stands now, I run the application on the input and save the results as a new file. To view the file, I have to use an *old* DOS program that displays the file at full screen. You can only view and open files, one at a time. I would like to incorporate my algorithms into a windows application that will display the input file and output file. I could use a wee bit of help on displaying the image. 2 things currently stand in my way. First is that my C++ programming knowledge does not cover Win32/MFC, only CLI apps (I have found I am now addicted to Java...). The second is due to the nature of the graphic file itself, it is a .img file, the format is 8 bits (char-type) for each pixel, with is no header (grayscale). I have seen various examples/tutorials on the net daeling with bmps, jpgs etc, but none with a custom file format. I am sure I have enough tidbits from various books to do a rudimentary application to at least open the files and show both. My problem is how do I actually read the image data and have it display on the screen properly. Any help is appriciated, MM

Share this post


Link to post
Share on other sites
Spoonbender    1258
Ok, first things first. If you have a good grasp of C++, Win32 should be easy enough to learn (Never used MFC, so don't know about that).

All you need to do is include windows.h, and then head over to http://msdn.microsoft.com and search for the functions you need. :P

It's just a big class library. Nothing really fancy about it, not even classes or namespaces. Just a huge collection of global functions.

A few more specific keywords to look for is GDI and HDC and HBITMAP.
GDI is the entire graphics subsystem of Win32. And it's more or less the only part you're going to need. A Device Context (DC, or HDC for a handle to one) represents the surface you're drawing on. It might be your client window, or it might be a bitmap in memory. In any case, using this HDC, you can call all the various drawing functions to construct the image you're loading. (SetPixel() is one way of doing it. Using that, you can just load each pixel's data from your file, and then call SetPixel on your HDC to plot that one pixel. There might be faster/more effective ways of doing it, but that's the best I can come up with right now.

Reading from a file should be simple enough C++. And since you know the file format, you can figure out which parts of the file represent which pixels, and then it's just a matter of plotting that onto your HDC.

Yeah, if you've never used Win32, a lot of this probably sounds like black magic, but it shouldn't be too complex once you've read up on it a bit :P

Share this post


Link to post
Share on other sites
MasterModakai    122
Thanks Spoonbender. I will take a look into the GDI. SetPixel()looks like it will be my candidate to show the pictures, as I really don't need it to be effiecient or fast, just work :). As far as black magic is concerned, it could be held together by chewing gum and bailing wire and it would be OK by me (as long as I can decipher it, that is) :D.

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this