gpt4 book ai didi

c# - 如何从 BitmapImage 创建 NotifyIcon?

转载 作者:行者123 更新时间:2023-11-30 15:34:04 26 4
gpt4 key购买 nike

我的资源字典中有一个资源项(一个 png 文件),我在多个地方使用它。现在我想将它用作应用程序的 NotifyIcon。但我不知道该怎么做。请问你有什么想法吗?

// my image:

var bitmap = new BitmapImage();
bitmap.UriSource = new Uri("pack://application:,,,/MyProj.Resources;component/Icons/Logo_48x48.png");

// and I try to do this:

var iconHandle = bitmap.GetHicon(); // but this line doesn't work
var ni = new NotifyIcon {
Icon = System.Drawing.Icon.FromHandle(iconHandle),
Visible = true
};

最佳答案

var sri = Application.GetResourceStream(
new Uri("pack://application:,,,/MyProj.Resources;component/Icons/Logo_48x48.png"));
var bitmap = new Bitmap(sri.Stream);
var handle = bitmap.GetHicon();
var ni = new NotifyIcon {
Icon = System.Drawing.Icon.FromHandle(handle),
Visible = true
};

关于c# - 如何从 BitmapImage 创建 NotifyIcon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16623200/

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