ImageList adds "hard" edge to images? (VB.Net2003)
If I add an image (png with 8-bit alpha drop shadow) directly to a button control it renders the alpha information properly against the button.
If I add images to an ImageList control (with ColorDepth set to Depth32Bit) then use the images on a TabControl or ToolBar the images have a hard single-colour alpha and a hard (in my case blue) edge around the png - which sucks on the colour "Control".
Is there anything I need to do to an ImageList or my forms to make it work with 8-bit alpha channels?
[505 byte] By [
frumbert] at [2007-12-16]
Load the images into the imagelist at runtime.
I usually add the images as Embedded Resource and load them up as follows:
| |
<System.Runtime.InteropServices.DllImport("gdi32.dll", SetLastError:=True)> _ Private Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean End Function Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim bmp1 As New Bitmap(Me.GetType, "1.png") Dim hIco1 As IntPtr = bmp1.GetHicon Dim ico1 As Icon = Icon.FromHandle(hIco1) ImageList1.Images.Add(bmp1) ImageList1.Images.Add(ico1) DeleteObject(hIco1) End Sub
|
You'll see that the bitmap has a blue tint, but the Icon from hIcon does not. Although the Icon does not have a blue tint, the Alpha is slightly darker than the original, but you usually won't notice this.
If possible add icons instead of pngs.
One note that might be useful. In VSNET2005 Beta 2, I've found that if I don't get good images (alpha blended, etc.) in ListViews unless the Color Depth is set to 32bit BEFORE adding any images. With it at 8bit, then adding images, then changing to 32bit, I get the dark pixels where the alpha blending is...
So you might try from scratch, a new image list, set the color depth to 32bit, THEN add your images.
I presume the runtime example above would probably work, too.
--Mike
I'm as yet to try out the use of icons instead of png files. For my immediate purpose using .ico files is fine because I have my button icon library in both .png and .ico format, however I'd like to use .png based images in the future. I don't really see why adding them runtime would be any different than adding them design time - i'm sure someone can clarify why the problem might not present itself when doing it runtime from embedded resources.
I always set the image depth and properties I want to use before starting, making sure the property matches the image depth I've set when creating the images. 16bit, 24bit and 32bit still leave the blue aliasing around the edges of png images.
I don't know what the problem is with the imagelist, I just know that the solution I offered works. There has been some work done on the imagelist for VS2005 and so this may not be necessary then, but for VS2002/3 it is.
The method outlined above does use pngs, but they are turned into icons before being added to the imagelist (as in ico1) otherwise you'll get blue tinted Alpha (as in bmp1).