在 C# 中显示带有 alpha 通道的 PNG
有没有办法在 C# 应用程序中正确显示带有 alpha 通道的图像(比如说 PNG)?感谢您的任何建议。
更新:
好吧,我的问题有点不准确。我想获得 Alpha 通道的真正透明度 - 不填充父级的背景颜色。在下图中我们可以看到支持透明度,但按钮位于图像下方的部分不可见。图像的 Alpha 通道是否可能具有真正的透明度?
Is there a way to properly display an image with alpha channel (let's say PNG) in C# application? Thank you for any suggestions.
UPDATE:
OK, my question was a bit unprecise. I'd like to acquire real transparency of alpha channel - not filling with the parent's background color. In the image below we can see that the transparency is supported, but the part of the button that lies below the image is not visible. Is it possible to have a real transparency of the alpha channel of an image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果那是winform则不行。
winforms中的“透明”并不是真正的透明。
您可以做的是创建一个alpha透明表单来绘制PNG并将其放置在正确的位置并绑定移动等。
http://www.codeproject.com/KB/GDI-plus/perpxalpha_sharp。 aspx
//opacity 是绘制图像的不透明度,值为 255 = 所有透明部分都将是 alpha/透明,就像原始 PNG 等一样。
编辑:或转到WPF。
If that is winforms then no.
"transparency" in winforms is not real transparency.
What you can do is to create a alphatransparent form that draws the PNG and position it at the correct location and bind move etc.
http://www.codeproject.com/KB/GDI-plus/perpxalpha_sharp.aspx
//opacity is the opacity that the image will be drawn with, a value of 255 = all transparent parts will be alpha/transparent just as much as the original PNG etc..
EDIT: OR GO TO WPF.
是的,System.Drawing.Image.FromFile("filename.png");
.NET 框架支持多种文件类型的透明度,我认为它不适用于 JPEG,但 PNG 应该没问题。
Yes, System.Drawing.Image.FromFile("filename.png");
The .NET framework supports transparency for multiple filetypes, I din't think it worked with JPEG, but PNG should be fine.
以下 MSDN 链接将有所帮助:
WPF:
http://msdn.microsoft.com/en-us/library/aa970062。视窗
:
http://msdn.microsoft.com/en-us/library/stf701f5。 aspx
关于System.Drawing.Image.FromFile方法:
The following MSDN link will help:
WPF:
http://msdn.microsoft.com/en-us/library/aa970062.aspx
Windows:
http://msdn.microsoft.com/en-us/library/stf701f5.aspx
About System.Drawing.Image.FromFile method: