[VisualPng] PNG image viewer for Win32



[download VisualPng]

Visual C++

For a long, long time, PNG developments were mainly driven from the Unix world. To be fair, a couple of the major Windows apps supported PNG from the early beginning. But for developers there was little to start with, like the problematic Win32 support in libpng. However, things have changed for the better. Since version 1.0.7 libpng fully supports MicroSoft Visual-C++, both with static linking to .lib's and dynamic run-time linking of .dll's.

VisualPng, a nice simple PNG image viewer, was developed to illustrate how these new libpng features can be used in a normal Win32 project. It is part of the libpng "contrib" distribution. If you just want the VisualPng executable, download it by clicking here.

You can use VisualPng as it is now, but most probably you want to use it as a starting point and extend it for your own purposes. First download the VisualPng sources zip-file by (shift-)clicking on the download-icon on the left. Extract the files in the archive into a directory of your own choice, but for the sake of this explanation, lets presume your program will bear the name PingPing, so call your subdirectory <something>/PingPing. Next step is to obtain the libpng archive (version >= 1.0.7) and store that in a sub-directory called ...\PingPing\libpng. Also get zlib and put it in ...\PingPing\zlib.

Now rename all the files VisualPng.* into PingPing.* and delete PingPing.dsw. Next, get the PingPing.c, PingPing.rc, and PingPing.dsp files into an editor and search/replace all occurances of VisualPng into PingPing. After this you can start VC++ by double-clicking PingPing.dsp, on which VisualC will (normally) ask if it should create PingPing.dsw: Great idea!

The settings of the workspace / project are as required for the libpng contrib distribution. But our directory structure here is different, so before we go any further, there are a couple of settings to change:

  • First, select "Project | Insert Project into workspace" and add the libpng\msvc\libpng.dsp (in later versions libpng\projects\msvc\libpng.dsp) and .../zlib.dsp projects to your PingPing workspace.
  • Next, if necessary, do "Project | Set active Project" and select PingPing.
  • Then "Project | Dependencies..." and make both libpng and zlib dependent on PingPing.
  • Choose between static and dynamic linking with "Build | Set Active Configuration..."; let's go for "PingPing - Win32 LIB" to link statically.
  • Change the include directories with "Project | Settings...", select in the file-window on the left the PingPing tree, click on the right the C/C++ tab, select the Category "PreProcessor" and change the Additional Include Directories textfield into ".\libpng,.\zlib".
  • Click the Link tab, select the Category "Input" and change the textfield "Additional Library Path" to ".\libpng\msvc\win32\libpng\lib" (or ".\libpng\projects\msvc\win32\libpng\lib").
  • Finally go to the far-right "Post-build step" tab and delete the Post-build command.
That should be all the required settings changes, but remember that you must make the same or similar changes for the other configurations, like the dynamic linking one or when you want to use the debugger. But you are now ready to compile and link with "Build | Rebuild All". All should go well (it rarely does ;-) and the result being your PingPing.exe binary. Test it by clicking the !-button or with "Build | Execute".

When this all went well, sit back and relax, and start thinking about what you would like your PingPing to do. From here you are all on your own, but you don't have to worry about how to read and write you PNG-files. Have a look at PngFile.c, which contains functions for opening, reading and writing the PNG images.

For the rest, as Nike says: JDI, or Just Do It !!!


P.S. As a follow-up to VisualPng, I wrote FishEye, a more full-featured viewer for BMP, GIF, JPEG, PNG and TIFF images. Click on the "fishy" icon below to learn more about FishEye.


[back to PNG] [FishEye image viewer] [Alpha channel PNG viewer] [Anti-aliasing and Amaya] [Adam7 interlacing demo] [PngSuite] [PingPong]


  Willem van Schaik, Calgary, June 2000     http://www.schaik.com/wwwillem.html