Display PNG with alpha channel in C#

女生的网名这么多〃 提交于 2019-12-04 03:52:25
Kristoffer Schroeder

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
PerPixelAlphaForm transparentImageForm = new PerPixelAlphaForm();
transparentImageForm.SetBitmap(<IMAGE GOES HERE>,<OPACITY GOES HERE>);

//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.

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.

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:

Managed GDI+ has built-in encoders and decoders that support the following file types:
- BMP
- GIF
- JPEG
- PNG
- TIFF

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!