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

[VB6] ImageList and the Safety Palette

$
0
0
This is really not a code sample as much as a technique to use in writing VB6 programs.

Many of the fancier GUI controls in VB6 accept images assigned from a companion ImageList control. Here I'll use the example of the Toolbar control. If we want to use the modern UX-themed versions of these controls based on Windows Common Controls we also need to use the older version 5 COMCTL32.OCX, but that's a separate issue.

Both the version 5 and version 6 VB ImageList controls are designed only to support images of 2, 16, or 256 colors. In the rare case of 2-color images the ImageList's BackColor property comes into play. Otherwise we normally only care about the MaskColor, when we want transparency.


Palettes

For either 16-color or 256-color bitmaps, all of the images must use the same palette. When they don't, you can end up with frustrating symptoms. Often the background or the whole images "go black" after you save your Project and when you run the compiled program.

I don't know why this happens, but it seems to be due to the way these controls persist the bitmaps into the Project's .FRX files.


Better ICO and BMP Files

The VS 6.0 graphics we got with VB6 were meant for another era. Many of them were holdovers from the Win3.x 16-bit era, and look it.

There are newer sets of icons and graphics available for newer versions of Visual Studio, though you'll have to work with them a little to use them with VB6. See:

Visual Studio Image Library

The smaller VS2012 Image Library.zip download there offers plenty to browse through for some better images.


Converting Images

If you want to use 24- or 32-bit images you won't be able to use the standard VB controls. So when you need to do that you'll need 3rd party controls or some other technique.

However quite a lot of the stuff in VS2012 Image Library.zip is usable after some tweaking.

The article Colors: The Safety Palette can be useful. The best thing I found there was a sample image called IC27432.gif under the subheading Get the Safety Palette.


Steps to Convert 24-bit Bitmaps

Go get IrfanView or another utility that can save and load .PAL files.

I grabbed 6 bitmaps from the VS download to demonstrate. Create a folder such as "Original 24-bit" and another such as "Standard 8-bit." Copy 24-bit BMP files to play with there.

Download IC27432.gif, open it in IrfanView, and export its palette. These are also included in the attached archive below.

Then for each bitmap file:

  • Open the bitmap from "Original 24-bit" in IrfanView.
  • Import the IC27432.pal, converting the image to 8-bit.
  • Save as... the new bitmap as BMP format into "Standard 8-bit."


Now you have 8-bit BMPs all using the Safety palette that you can use safely in ImageList controls!

Be sure you set the MaskColor of your ImageLists as well. Many of these use magenta (&H00FF00FF&) as the MaskColor instead of the old default gray shade (&H00C0C0C0&)


Results

Not too bad really. Note that there is only so much you can do with 16x16 images to make them look good though.

Name:  sshot.png
Views: 58
Size:  10.7 KB

Here I don't really care for the shading on the Left-justify icon, it's a little dark. But you can always tweak that as long as you avoid altering the palette.

The archive has the demo Project as well as the BMPs' before and after versions.
Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 1463

Trending Articles



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