There are lots of image viewer and one is MeeSoft Image Analyzer. It supports lots of image format and displayed pixels are not anti-aliased.
There are also lots of image format. Though in here, I want wide-spread, loseless, support binary packed pixel and royalty-free image format. I choose PNG file format.
To manipulate PNG file format, there is LibPng for Windows. Also there is C++ wrapper project png++. To use LibPng, zlib is also needed for compression/decompression.
To setup, you need to download binaries and developer files from above link and extract it to some place. I extracted at 3rdParty folder.
Then modify the project's 'Additional Include Directories' with below directories. Prefixed "../" depends on the relative depth between project to the 3rdParty folder.
"../../../3rdParty/libpng-1.2.37/include"; "../../../3rdParty/zlib-1.2.3/include"; "../../../3rdParty/png++-0.2.5";
Then modify Library Directories with below path.
"../../../3rdParty/libpng-1.2.37/lib"
Then add '__Win32' to the Processor Definition. This is for png++ and without it, you will see below error.
/3rdparty/png++-0.2.5/config.hpp(57) : fatal error C1189: #error : Byte-order could not be detected.
There is one more step that needs attention on zlib. The zlib is trying to include unistd.h in Windows and there seems no other way but to comments the line out. Maybe I missed a step in the setup. Anyway with this line removed, it make the project compile and link though I don't know the implication. Refer below for the change.
zconf.h at line 289 #if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */ # includeWhen the project is executed, it will look for the dlls for libpng and zlib. This can go to the system32 folder but in here I copied those file to the output folder using 'Post build event' as below./* for off_t */ //# include /* for SEEK_* and off_t */ // commented out ... #endif
xcopy "../../../3rdParty/libpng-1.2.37/bin/libpng12.dll" "$(TargetDir)" /Y xcopy "../../../3rdParty/zlib-1.2.3/bin/zlib1.dll" "$(TargetDir)" /YNow all set and code like below will save any image to png file.
#pragma warning( push, 3 ) #pragma warning( disable : 4996 4267 4355 ) // there are number warnings that may not be a problem at all ... #include < png.hpp > #pragma warning( pop ) #include "Image.hpp" // Image<> and BinaryImage<> are defined in here #include < iostream > #pragma comment(lib, "libpng.lib" ) // Most of this template class comes from png++ example. template < typename TImage, typename PngPixelType > class ImagePngWriter : public png::generator < PngPixelType, ImagePngWriter < TImage,PngPixelType > > { public: ImagePngWriter( TImage& image ) : png::generator < PngPixelType, ImagePngWriter > ( image.GetWidth(), image.GetHeight() ), m_Image( image ) {} png::byte* get_next_row(size_t pos) { return reinterpret_cast < png::byte* > ( m_Image.GetPixelPtr( 0, (int)pos ) ); } void Write( const char *filename ) { std::ofstream file( filename, std::ios::binary); write(file); } private: TImage& m_Image; }; usgae Image< boost::uint8_t > image( 640, 480 ); ... ImagePngWriter< Image< boost::uint8_t >, png::gray_pixel > pngWriter( image ); pngWriter.Write( "Gray.png" ); BinaryImage<> image( 640, 480 ); ... ImagePngWriter< BinaryImage<>, png::gray_pixel_1 > pngWriter( image ); pngWriter.Write( "Binary.png" );