gpt4 book ai didi

c# - 在代码中将透明PNG转换为System.Drawing.Icon

转载 作者:太空狗 更新时间:2023-10-29 21:30:31 24 4
gpt4 key购买 nike

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

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

最佳答案

你可以写

Icon.FromHandle(image.GetHIcon())

You'll need to explicitly destroy the icon when you're done with it :

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

DestroyIcon(newIcon.Handle);

关于c# - 在代码中将透明PNG转换为System.Drawing.Icon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4899864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com