pngscreenshot 1.0


Today was another one of those lazy days where I couldn't bring myself to get anything constructive done on the game. So instead I added the ability to take a screenshot from inside my game, and write it out to disk. DirectX 8 makes this easy; you just GetFrontBuffer() and D3DXSaveSurfaceToFile().

Unfortunately, D3DXSaveSurfaceToFile() only supports BMP and DDS files, and won't write compressed files. And since GetFrontBuffer() only supports D3DFMT_A8R8G8B8, a BMP screenshot of a 1600x1200 screen is over 7.6MB! Eek!

Since I was already using Zlib, I realized that all I had to do was add libpng to my project and hack out a file writer from their example code. An hour later and it was up and running, generating simple but correct PNG files. Now those same 1600x1200 screenshots are only about 600k. Ahh, much better!

But I still wasn't done procrastinating for the day. I decided to turn the code into a cheap and sleazy library for Flipcode, and post it here. To share with the whole world. Hooray!

The pngscreenshot web page is here:
And you can download a fresh copy of the source code here:

Notes on pngscreenshot

What are PNG files?

The authors of PNG do a much better job describing it than I can. But, in a nutshell, a PNG file is a lossless compressed image file format. Unlike JPG files, PNG files are lossless—a PNG file will reproduce the original file exactly. Unlike GIF files, PNG files are unencumbered by patents, and support truecolor images (GIF is limited to 256 colors).

How To Use pngscreenshot

And you're ready to rock!


Here's the license:

** Copyright (C) 2003 Larry Hastings
** This software is provided 'as-is', without any express or implied warranty.
** In no event will the authors be held liable for any damages arising from
** the use of this software.
** Permission is granted to anyone to use this software for any purpose,
** including commercial applications, and to alter it and redistribute
** it freely, subject to the following restrictions:
** 1. The origin of this software must not be misrepresented; you must not
**    claim that you wrote the original software. If you use this software
**    in a product, an acknowledgment in the product documentation would be
**    appreciated but is not required.
** 2. Altered source versions must be plainly marked as such, and must not be
**    misrepresented as being the original software.
** 3. This notice may not be removed or altered from any source distribution.
** The pngscreenshot homepage is here:
In non-legalese, my goal was to allow you to do anything you like with the software, except claim that you wrote the original version. If my license prevents you from doing something you'd like to do, contact me (my email address is in the source) and we can discuss it.

Version History

Thursday, August 14th, 2003
Initial public release.

Happy screenshooting!