icons on XP and W2k

K

+ Kennedy Kok +

I have a .NET application which is targeted at both W2k and XP. My form's
icons are XP style icons 32-bit. When it is running on W2k, the icons do not
look correct. I understand that W2k does not support 32-bit icons with 8-bit
alpha channels. My question is what can I do so that when my app is running
on XP - it will display the XP icon and when it is running on W2k - it will
display a 256-colored icon?

Would I have to resort to detecting through code if I am running in W2k and
then switch the icon property through code? Or is there a better way?

Thanks

Kennedy
 
R

ryanyoder

I came up with a workaround for this problem.
I wrote a method which made a 24 bit copy of an image against a static
colored background which i set to the color of the toolbar itself.
I then used this image on my toolbar and it works fine for me.
You get a 24 bit antialiased image but the only problem is that the
image is now rectangular and doesnt draw when "disabled" properly.
 
R

ryanyoder

/// <summary>
/// Creates a 24 bit version of a 32 bit image with alpha
transparency.
/// The antialiasing is retained by setting the background of the
image to the backColor
/// property.
/// This is useful with the buggy 32bpp implementation in the DotNet
ImageList and ToolBar.
/// Set your toolbar to 24 bit and pass all bitmaps through this
converter with the backColor
/// set to the containing controls backColor and you get alpha for
free.
/// </summary>
/// <param name="bmp">the bmp to copy</param>
/// <param name="backColor">the background color for
anti-aliasing</param>
/// <returns>a new Bitmap in 24 bit format</returns>
private Bitmap Create24BitFromAlpha(Bitmap bmp, Color backColor)
{
Bitmap newBmp = new Bitmap(bmp.Width, bmp.Height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(newBmp);
g.FillRectangle(new SolidBrush(backColor), 0, 0, bmp.Width,
bmp.Height);
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
g.Dispose();
return newBmp;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top