在 GDI 中绘制具有自定义透明度的图像+
我正在使用 Drawing.Graphics 对象和 DrawImage() 函数将大量图像(所有尺寸=24x24 Pixelformat=32BppPArgb)绘制到控件上。可以在我的应用程序中缩小,这意味着 Graphics 对象附加了一个变换矩阵,可以控制缩放和平移。
当缩放比例低于 50% 时,绘制这些图标是没有意义的,但我想让从绘制图标到不绘制图标的过渡更加平滑。即,从 70% 开始,应该使用额外的透明度系数绘制图标,以便它们在 50% 时变得完全透明。
如何绘制具有额外透明度的位图,而不需要比 DrawImage() 花费更长的时间?
谢谢, 大卫
I'm drawing lots of images (all of them dimensions=24x24 pixelformat=32BppPArgb) onto a Control using a Drawing.Graphics object and the DrawImage() function. It's possible to zoom out in my application which means that the Graphics object has a Transform Matrix attached to it which controls both zooming and panning.
There's no point in drawing these icons when the zoom drops below 50%, but I'd like to make the transition from drawing icons to not drawing icons smoother. I.e., starting at 70%, icons should be drawn with an additional transparency factor so that they will become completely transparent at 50%.
How can I draw a bitmap with an additional transparency without it taking significantly longer than DrawImage()?
Thanks,
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需创建一个适当的 ColorMatrix,用它初始化一个 ImageAttributes 对象,并将该 ImageAttributes 对象传递给 Graphics.DrawImage 的重载版本之一。此示例将为您提供 50% 的透明度:
You just create an appropriate ColorMatrix, initialize a ImageAttributes object with it and pass that ImageAttributes object to one of the overloaded version of Graphics.DrawImage. This sample will give you 50% transparancy: