我正在开发一个利用 Windows 7(和 Vista)任务栏功能的程序。现在我有一个自定义位图,它将显示在任务栏缩略图 中。位图以编程方式创建并成功显示。我遇到的唯一“问题”是想在该图像中使用透明,缩略图也应该显示透明。但没有任何成功,导致标准的Light-Gray颜色。
我已经看到程序成功地在图像中变得透明的证据:
- 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;
最佳答案
您的位图是什么像素格式?如果它没有 alpha channel ,您将无法在图像中存储透明度信息。
以下是如何创建带 alpha channel 的位图并使其默认透明:
Bitmap image = new Bitmap(width, height, PixelFormat.Format32bppArgb);
using(Graphics graphics = Graphics.FromImage(image))
{
graphics.Clear(Color.Transparent);
// Draw your stuff
}
然后您可以绘制任何您想要的东西,包括使用 alpha channel 的半透明内容。
另请注意,如果您尝试在现有的不透明物体上绘制透明度(比如打洞),则需要更改合成模式:
graphics.CompositingMode = CompositingMode.SourceCopy;
这将使您使用的任何颜色覆盖图像中的颜色,而不是与之混合。
关于c# - 如何使任务栏缩略图上的区域在 Windows 7 中显示为透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5132760/