开发者

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

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:

  • http://blog.miranda.or.at/wp-content/uploads/2010/05/taskbar.png
  • http://www.addictivetips.com/wp-content/uploads/2010/04/TaskbarRSS.png
  • http://www.addictivetips.com/wp-content/uploads/2009/10/Thumbnail1.png

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 allo开发者_StackOverflowwed.

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;


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.


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜