hardcodet / wpf-notifyicon

NotifyIcon (aka system tray icon or taskbar icon) for the WPF platform
Other
810 stars 125 forks source link

Allow IconSource to be a concrete BitmapSource #71

Open tmr0861 opened 2 years ago

tmr0861 commented 2 years ago

By adding a BitmapSource.ToIcon extension method to util.cs, along a check in ImageSource.ToIcon to look for the concrete type and call said method, the IconSource can be bound to a concrete BitmapSource type. This allows for dynamic drawing of the icon image by my application.

There may be better ways to do this, but this seemed pretty simple.

Lakritzator commented 2 years ago

Thank you for your interest in the repository, and for your contribution.

The limited possibilities for defining an icon definitively need some love, in fact I already talked about this for ages here, but also in #24 this is seen. I already prepared some work, last April, but somehow didn't get to it yet.

It's not rocket science, but I do not think it's "pretty simple", for instance your PR would cause memory leaks as you forget to dispose the bitmap created here.

Also it might not be the most performant solution, so I like to propose I come up with a more flexible and better solution. I might step up my efforts, but it depends on how much time I can free up.

Lakritzator commented 2 years ago

I even forgot to mention the hbitmap leak...

tmr0861 commented 2 years ago

Thank you for your interest in the repository, and for your contribution.

The limited possibilities for defining an icon definitively need some love, in fact I already talked about this for ages here, but also in #24 this is seen. I already prepared some work, last April, but somehow didn't get to it yet.

It's not rocket science, but I do not think it's "pretty simple", for instance your PR would cause memory leaks as you forget to dispose the bitmap created here.

Also it might not be the most performant solution, so I like to propose I come up with a more flexible and better solution. I might step up my efforts, but it depends on how much time I can free up.

Thanks for considering the request. I look forward to seeing this done the right way so I can learn more. Thanks again!

maxpavlov commented 2 years ago

Until this PR is reviewed, finalized, and merged, the only way of adding an icon for the Notification area (basically the main product driver behind this library), is via embedded application resources. This is casting users unable to dynamically generate and use icons. This might seem like a non-common case, but the limitation is rather artificial and comes only from the following line of code in the current master branch:

Utils.cs, Line 174:

StreamResourceInfo streamInfo = Application.GetResourceStream(uri);

This GetResourceStream makes sure only icons embedded as Resources could be used.

I would love this PR to be merged as with it, any BitmapImage could be supplied.