2 Attachment(s)
[VB6] ImageList and the Safety Palette
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.
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.
Re: [VB6] ImageList and the Safety Palette
Its easy to make colorful icons. You can put a bitmap and you get a multiple icon file. I used before years in a form in vb5.
Look here:
http://www.vbaccelerator.com/home/VB...or/article.asp
Re: [VB6] ImageList and the Safety Palette
This thread isn't about creating true-color or alpha icons.
They don't help you anyway unless you use non-standard controls:
Quote:
Originally Posted by
dilettante
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 the vbAccelerator controls are notorious for problems of various kinds. Many of them have incomplete type information preventing them from being used with reg-free COM, which suggests they have other flaws in their implementation.
You can also shop around for 3rd party commercial controls.
However the point of this was to address an issue that comes up often when using the controls shipped with VB6, and that's the problem of the bitmaps "turning black" or otherwise falling apart on people due to palette problems.
Re: [VB6] ImageList and the Safety Palette
I evaluate the above code (from vbaccelerator.com) and I found a tiny error...
In the bottom of CreateIcon Sub is the part who read a listbox for user sizes for icons. Listcount always are +1 from upper boundary of item list (because the list start from 0...end end to listcount-1). So just put minus one in the end of the for statement
Code:
Private Sub createIcon(cFI As cFileIcon)
Dim lIndex As Long
Dim i As Long
Dim iPos As Long
Dim lWidth As Long
Dim lHeight As Long
Dim sWidthHeight As String
If (chkSize(0).Value = vbChecked) Then
lIndex = cFI.IconIndex(16, 16, 32)
If (lIndex = 0) Then
lIndex = cFI.AddImage(16, 16, 32)
End If
createIconAtSize cFI, lIndex, 16, 16
End If
If (chkSize(1).Value = vbChecked) Then
lIndex = cFI.IconIndex(24, 24, 32)
If (lIndex = 0) Then
lIndex = cFI.AddImage(24, 24, 32)
End If
createIconAtSize cFI, lIndex, 24, 24
End If
If (chkSize(2).Value = vbChecked) Then
lIndex = cFI.IconIndex(32, 32, 32)
If (lIndex = 0) Then
lIndex = cFI.AddImage(32, 32, 32)
End If
createIconAtSize cFI, lIndex, 32, 32
End If
If (chkSize(3).Value = vbChecked) Then
lIndex = cFI.IconIndex(48, 48, 32)
If (lIndex = 0) Then
lIndex = cFI.AddImage(48, 48, 32)
End If
createIconAtSize cFI, lIndex, 48, 48
End If
If (chkSize(4).Value = vbChecked) Then
For i = 0 To lstCustom.ListCount - 1 ' Here is OK..
sWidthHeight = lstCustom.List(i)
iPos = InStr(sWidthHeight, "x")
lWidth = CLng(Left(sWidthHeight, iPos - 1))
lHeight = CLng(Mid(sWidthHeight, iPos + 1))
lIndex = cFI.IconIndex(lWidth, lHeight, 32)
If (lIndex = 0) Then
lIndex = cFI.AddImage(lWidth, lHeight, 32)
End If
createIconAtSize cFI, lIndex, lWidth, lHeight
Next i
End If
End Sub
Re: [VB6] ImageList and the Safety Palette
I saw your reply.
I use this big icon for form icon. This is good for the big screens of today..
I will try your code. That is what i can do now;
Re: [VB6] ImageList and the Safety Palette
Tinkering with this I have made an embarassing discovery though:
It appears that the 24-bit images I took from the VS2012 pack were carefully composed using only Safe Palette colors in the first place.
This means they should work fine as is in VB ImageList controls without being converted to 256-color (8-bit) images! Because they don't have to carry the baggage of a palette, they're smaller than my 8-bit BMPs as well.
So in the end it looks like the main reason to use the Safe Palette is for creating your own image bitmaps. And that means you need to use an image editor that can load palettes to help you restrict your color set.
I hope somebody who understands this topic better will add to it.
1 Attachment(s)
Re: [VB6] ImageList and the Safety Palette
I do an experiment. I have for some days Vb6, and vb5 for years, so I remember that V5 can handle big icons..I check vb6 and vb6 cannot load from propertis list form. So I prepare one form with a 128x128 icon in vb5 and then I loaded in vb6. And i make an exe file from that. Look the form in the zip file.So is the IDE the problem.
:mad:
Re: [VB6] ImageList and the Safety Palette
You seem to be off on a tangeant here. I'm not talking about Form or program icons, or really about icons at all. This thread is about Toolbar, Treeview, ListView, and similar controls that use ImageList controls to hold their bitmaps.
If you have questions about Form icons you might start a question thread instead.
I'll admit immediately I'm not a graphics guy. I just wanted to show how to get around a common problem with ImageList controls.
As far as I can tell the technique works fine, it just isn't actually needed with button BMPs from the later VS image packs.
Re: [VB6] ImageList and the Safety Palette
You are right; I am of the topic...for a bit. The common is the icon creation..the scope is different. You see the trick with a form made it in vb5 and loaded in vb6? Can you do that with other method?