如何使任务栏缩略图上的某个区域在 Windows 7 中显示为透明?
我正在开发一个利用 Windows 7(和 Vista)任务栏功能的程序。现在我有一个自定义位图,它将显示在任务栏缩略图中。位图以编程方式创建并成功显示。我遇到的唯一“问题”是想在该图像中使用透明,它也应该在缩略图中显示为透明。但没有任何成功,导致标准的浅灰色颜色。
我已经看到证据表明程序成功地在图像中变得透明:
- 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
现在我的问题是:如何在缩略图中变得透明?
我将使用 Graphics
类填充图像,因此任何内容都是允许的。
我应该提到,我使用 Windows® API Code Pack,它使用 GetHbitmap
到 将图像设置为缩略图。
编辑:
为了使它完整,这是我正在使用 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;
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 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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的位图是什么像素格式?如果它没有 Alpha 通道,您将无法在图像中存储透明度信息。
以下是如何创建带有 Alpha 通道的位图并使其默认透明:
然后您可以绘制任何您想要的东西,包括使用 Alpha 通道的半透明内容。
另请注意,如果您尝试在现有不透明的东西上绘制透明度(例如打一个洞),则需要更改合成模式:
这将使您使用的任何颜色覆盖图像中的颜色而不是与其混合。
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:
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:
This will make whatever color you use to overwrite the one in the image rather than blending with it.
System.Drawing.Bitmap 支持 Alpha 级别。所以最简单的方法是
你也可以通过替换 Brushes.Transparent 来获得部分透明度
System.Drawing.Bitmap supports an alpha level. So the simplest way is
however you can also have partial transparency by replacing Brushes.Transparent with