在代码中将透明PNG转换为System.Drawing.Icon [英] Convert transparent PNG to System.Drawing.Icon in code

查看:116
本文介绍了在代码中将透明PNG转换为System.Drawing.Icon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将透明的PNG图像作为ImageSource转换为尊重PNG透明度的System.Drawing.Icon。

I'm looking to convert a transparent PNG image as an ImageSource into a System.Drawing.Icon that respects the transparency of the PNG.

WPF可以某种方式做如果您将窗口的图标设置为PNG ImageSource,则在内部进行此操作,但有什么方法可以手动执行此操作?具体来说,我需要这个来设置系统托盘通知图标,我真的想避免使用笨拙的.ico格式资源。

WPF can somehow do this internally if you set the icon for a window to a PNG ImageSource, but is there any way I can do this manually? Specifically I need this to set the system tray notify icon and I really want to avoid using clumsy .ico format resources.

推荐答案

你可以写

Icon.FromHandle(image.GetHIcon())

完成后,您需要明确销毁图标

[DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);

DestroyIcon(newIcon.Handle);

这篇关于在代码中将透明PNG转换为System.Drawing.Icon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆