[vb6] Enhancing VB's StdPicture Object to Support GDI+
This is my second version of the logic first introduced here. That version will no longer be supported.
In short, this is a stand-alone class. It can enable VB image controls, forms, picture boxes, etc to display other image formats VB cannot support. It can display images with higher quality scaling and lots of options. This class even has the ability to treat an image control like a picture box -- draw whatever you want, wherever you want, within the image control. For those that only need to load images for simple display, the call is as easy as the following, not much different than VB's LoadPicture. The class can load files, arrays, Windows image handles and more.
Code:
Dim cLoader As New StdPicEx2
Set Image1.Picture = cLoader.LoadPictureEx([source])
This second attempt offers so much more than the previous one:
1. GDI+ can be used for improved scaling for all image formats
2. Better (far more complex) thunk used for managing stdPictures
3. Callbacks can be requested so you can respond to the entire rendering process
4. Can attach GDI+ image attributes (grayscaling/blending) to managed images
5. Can modify GDI+ graphics object during callbacks, i.e., rotation (sample in attached zip)
6. Can cache original image format and retrieve for saving to file
7. Can create resized, high quality scaled bitmaps and/or icons via CopyStdPicture
8. Can return embedded image DPI value
9. Written to address backward and future version compatibility
10. Only affects those stdPicture objects that are managed
As with the previous version of this class, many image formats are supported:
- BMP. Those with valid alpha channels can be rendered with transparency. VB-unsupported formats are supported and include: those with v4/v5 bitmap headers and those with JPG/PNG compression
- JPG. CMYK color-space supported via GDI+. Camera-orientation correction supported
- ICO. Alphablended and PNG-encoded icons are supported
- CUR. Same as icons and also color cursors can be returned while in IDE, unlike VB
- WMF/EMF. Not directly managed, no need. Non-placeable WMFs are supported
- PNG. Supported via GDI+, APNG is now supported
- TIF. Supported via GDI+, multi-page navigation supported
- GIF. Rendering of individual frames (animated GIF) supported via GDI+
- For any other format, if you can convert it to bitmap (alpha channel or not), then supported
The enclosed class offers several methods for managing stdPictures, among those:
- LoadPictureEx creates a new stdPicture object by file, array or handle and supports unicode file names
- LoadResPictureEx is a slightly extended version of VB's LoadResPicture function
- UnmanageStdPicture removes existing stdPicture objects from management
- CopyStdPicture can copy/create/convert icons and bitmaps with/without alpha channels
- PaintPictureEx is a substitute for VB's PaintPicture, BitBlt, StretchBlt, AlphaBlend
- SetCallBacks enables receiving one or more of the 4 available callbacks
- SetImageAttributesHandle associates user-provided GDI+ attributes with a managed image
- PictureTypeEx can return the actual image format, i.e., PNG, JPG, TIF, etc
- SetFrameGifPng/GetGifPngAnimationInfo applies for animated GIF/PNG when managed
- SetPageTIF applies for muliti-page TIFs when managed
- GetFramePageCount will return count for managed GIF/TIF
- several other methods are available for optional settings
--------------------------------------------------------------------------
The attachments below are the sample project (all in one zip exceeds forum limits mostly due to sample images). The 1st three below must be unzipped in same folder. The stdPicEx2 class is a stand-alone class included in the zips. The rest of the files are to show-off some of its capabilities. The 4th one below is documentation that you may be interested in. It also includes the thunk raw source before I compiled it with NASM.
Project not guaranteed to be compatible with systems lower than XP (GDI+ required), but XP/Win2K and above should be supported. GDI+ v1.0 can be redistributed to those older systems.
The sample project includes GIF/APNG animation, PNG/TIF support, alphablended icon support, JPG camera-orientation correction, zoom/pan example, GDI+ attribute usage, and more. Just FYI: If the StdPicEx2 class is ever included as its own attachment below, it will be an updated version that may not be in the sample project.
Latest changes... 25 April 2018
Many changes made. See posts #29 & #30 for more information. Previous version should not be used.
Last edited by LaVolpe; Apr 25th, 2020 at 12:59 PM.
Reason: updated project
Insomnia is just a byproduct of, "It can't be done"