Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1470

[VB6] IcoWriter - Yet another "hIcon to array/file saver"

$
0
0
IcoWriter is a VB6 class that can be used to save hIcon handles into ICO format. it can provide them as a Byte array or write them to a disk file you provide a name for.

Details

Unlike some sample code IcoWriter will save multiple images of different dimensions and color depths as a single ICO.

It does not handle "Vista" icon images (256x256 PNG images) but it handles most square and rectangular images below 256 pixels in both dimensions. I don't recommend it for anything larger than 48x48 though. Color depths supported are 1-bpp, 4-bpp, 8-bpp, 24-bpp, and 32-bpp with alpha channel.

You might obtain hIcon handles in several different ways in a VB6 program. IcoWriter is offered here embedded in a demo application that uses several of these.

It is also possible to load other bitmap images formats and use them via an ImageList control. The demo does this with PNG source images, though as written that requires WIA 2.0. You could modify the demo code to use GDI+ directly too.

IcoWriter takes a stab (ok, multiple stabs) at handling color depth reduction to get somewhat better results than it might otherwise produce. However "garbage in, garbage out" and so this isn't perfect. Especially for creating 1-bpp images out of 24-bpp source images!

A proper color quantization algorithm might improve on IcoWriter's current results. But I'm no Graphics Guru so I'll live with what I have for now. ;)


Requirements

VB6 to run or compile the demo of course.

Windows XP or later to work with 32-bpp alpha channel ("XP") icon images.

WIA 2.0 (included with Vista and later, can be installed into Windows XP SP 1 or later). This is just for the demo, IcoWriter does not use WIA.


Testing the demo

If you have a PC meeting the requirements, everything should be there. Just unzip the attachment into a folder and open it in VB6 by "double clicking" on the .VBP file. Then you should be able to run it. Do people still have Explorer set to double-click mode... in 2015?

Check the created Saved folder for the results. These are best examined using IcoFX or another decent icon editor.

The attachment's size is largely made up of source images.
Attached Files

Viewing all articles
Browse latest Browse all 1470

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>