Closed kurmachu closed 2 years ago
Update: the following code does cause a crash so I guess it has to do with saving?
public BitmapImage Image { //Using(?) https://stackoverflow.com/questions/26260654/wpf-converting-bitmap-to-imagesource
get
{
if (_Image == null)
{
ShellFile shellFile = ShellFile.FromFilePath(Path);
Bitmap bitmap = shellFile.Thumbnail.LargeBitmap;
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); //This causes the issue???
bitmap.Dispose();
ms.Dispose();
bitmap = (Bitmap)Bitmap.FromFile("Assets/ic_programnew.ico");
ms = new MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bitmap.Dispose();
shellFile.Dispose();
ms.Seek(0, SeekOrigin.Begin);
_Image = new BitmapImage();
_Image.ImageFailed += (s, e) =>
{
Debug.WriteLine(e.ErrorMessage);
};
_Image.SetSourceAsync(ms.AsRandomAccessStream()).Completed += (s, e) =>
{
ms.Dispose();
};
}
return _Image;
}
}
I am still creating the tray icon in the same method as the original comment.
I'm not sure what ShellFile
is or why issues with saving a shellfile to a bitmap is logged here? (since none of those APIs are WinUIEx APIs).
To set the trayicon you must use an .ico
file, so don't really get the relevancy with the Bitmap format you're using either?
When using a
TrayIcon
with the thumbnails gathered from https://github.com/contre/Windows-API-Code-Pack-1.1, closing a window causesSystem.ExecutionEngineException
. Interestingly, loading the image itself is not enough, it only occurs when the image is displayed and then closed.I'm setting up a tray icon like this:
And loading the icons into an image via binding and:
The issue only occurs if both the shell icons and the tray icon are used, there is no issue if only one is used.
I understand that this is probably not a fault of this project, but any help would be appreciated.