Fix bitmap creation error in Explorer plugin shell integration

This commit is contained in:
Yusyuriv 2024-05-30 22:44:52 +06:00
parent a8e2927f2a
commit 0969fc12cb
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0

View file

@ -285,19 +285,28 @@ public static class ShellContextMenuDisplayHelper
private static BitmapSource GetBitmapSourceFromHBitmap(IntPtr hBitmap)
{
var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(32, 32)
);
if (!DeleteObject(hBitmap))
try
{
throw new Exception("Failed to delete HBitmap.");
var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(32, 32)
);
if (!DeleteObject(hBitmap))
{
throw new Exception("Failed to delete HBitmap.");
}
return bitmapSource;
}
catch (COMException)
{
// ignore
}
return bitmapSource;
return null;
}
}