How can I make a region on my taskbar thumbnail appear transparent in Windows 7?

856 views Asked by At

I'm developing a program that makes use of Windows 7 (and Vista) taskbar features. Right now I have a custom bitmap that will be shown in the taskbar thumbnail. The bitmap is created programmatic and shows up successfully. The only 'problem' I'm having is that want to use transparent in that image, which should show transparent in the thumbnail too. But without any success, resulting in the standard Light-Gray color.

I've seen evidence that programs successfully get transparent in the their images:


Now is my question: how do I get transparent in my thumbnail image?


I'll be filling the image with the Graphics class, so anything is allowed.
I should mention that I use Windows® API Code Pack, which uses GetHbitmap to set the image as thumbnail.

EDIT:
Just to make it complete, this is the code I'm using atm:

Bitmap bmp = new Bitmap(197, 119);

Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, bmp.Width, bmp.Height));  // Transparent is actually light-gray;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
g.DrawString("Information:", fontHeader, brush, new PointF(5, 5));

bmp.MakeTransparent(Color.Red);
return bmp;
2

There are 2 answers

0
Coincoin On

What pixel format is your Bitmap? If it has no alpha channel, you won't be able to store transparency information in your image.

Here is how to create a bitmap with an alpha channel and make it transparent by default:

Bitmap image = new Bitmap(width, height, PixelFormat.Format32bppArgb);
using(Graphics graphics = Graphics.FromImage(image))
{
    graphics.Clear(Color.Transparent);
    // Draw your stuff
}

You can then draw anything you want, including semi transparent stuff using the alpha channel.

Also note that if you are trying to paint transparency over existing opaque stuff (say to make a hole), you need to change compositing mode:

graphics.CompositingMode = CompositingMode.SourceCopy;

This will make whatever color you use to overwrite the one in the image rather than blending with it.

0
Chris McGrath On

System.Drawing.Bitmap supports an alpha level. So the simplest way is

Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.Transparent, new Rectangle(0, 0, bmp.Width, bmp.Height));  // Transparent is actually light-gray;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
g.DrawString("Information:", fontHeader, brush, new PointF(5, 5));

however you can also have partial transparency by replacing Brushes.Transparent with

new SolidBrush(Color.FromArgb(150, 255, 255, 255));