如何从BitmapImage创建一个NotifyIcon
本文关键字:一个 NotifyIcon BitmapImage 创建 | 更新日期: 2023-09-27 18:14:07
我有一个资源项目(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
};