I recycled the code from an old MS KB article on VB 4.0 screen captures to create a Class I call MSKBCapture.
This Class has methods to capture a Form, a Form's client area, the screen, another window by handle, or the active window into a StdPicture object (or the Picture property of a PictureBox or Image, etc.). It can also print a StdPicture to a printer filling the page.
After that I wanted to be able to save a StdPicture (such as a capture) to disk in GIF, PNG, JPEG, etc. A StdPicture can already be saved to disk as a BMP.
To do this I chose to use the WIA 2.0 library, which means XP SP1 or later is required. This is great, but WIA has no method to extract from a StdPicture into one of its objects, even though it can convert from WIA to a StdPicture on its own.
I tracked down Edanmo's mdlPictToArray.bas and modified it into a Class Picture2BMP with a Save method to save a StdPicture into a Byte array in BMP file format. This byte array can be loaded into WIA just fine, allowing me to either save to disk or into a Byte array in GIF, PNG, JPEG, or TIFF formats.
Dependencies:
MSKBCapture.cls - none.
Picture2BMP.cls - Edanmo's OLE interfaces and functions typelib (olelib.tlb).
Some of this functionality I hunted far and wide for. I really wanted no dependencies, but in the end I settled for a few. However in addition to the captures there is enough here to let you load and save images from either files or Byte arrays in several image formats, lots of this coming from WIA.
The demo project just displays a Form with some controls on it, and captures to disk when you hit Escape. You can change the program to switch the saved image format or what item is captured.
Last edited by dilettante; Jan 4th, 2009 at 11:04 PM.