gpt4 book ai didi

c# - 从 C# 中的图标文件创建 System.Windows.Media.ImageSource?

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

我正在使用 C# 编写 WPF 应用程序。有时我需要更改通知程序图标;

我是这样实现图标的:

<tn:NotifyIcon x:Name="MyNotifyIcon" 
Text="Title"
Icon="Resources/logo/Error.ico"/>

我的解决方案是更改图标,MyNotifyIcon.Icon 的类型是ImageSource,我想通过图标文件获取。我可以找到这样做的方法。

有人知道怎么做吗?或者有什么其他的解决办法?

很快,我有一个像/Resource/logo.icon 这样的地址,我想得到一个System.Windows.Media.ImageSource

最佳答案

您可以使用 BitmapImage 类:

        // Create the source
BitmapImage img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri("./Resource/logo/logo.icon");
img.EndInit();


BitmapImage 类继承自 ImageSource 类,这意味着您可以将 BitmapImage 对象传递给 NotifyIcon.Icon 作为:


NI.Icon = img;

关于c# - 从 C# 中的图标文件创建 System.Windows.Media.ImageSource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23817724/

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