mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-12-24 02:00:55 +08:00
handle icon exception
This commit is contained in:
@@ -58,8 +58,8 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
(int) (128 * scale.Vertical),
|
||||
ThumbnailOptions.ScaleUp);
|
||||
|
||||
var source = icon.ToBitmapSource();
|
||||
icon.Dispose();
|
||||
var source = icon?.ToBitmapSource();
|
||||
icon?.Dispose();
|
||||
|
||||
Dispatcher.BeginInvoke(new Action(() => image.Source = source));
|
||||
});
|
||||
|
||||
@@ -56,6 +56,9 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
{
|
||||
var hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);
|
||||
|
||||
if (hBitmap == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
// return a System.Drawing.Bitmap from the hBitmap
|
||||
@@ -114,25 +117,23 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
|
||||
private static IntPtr GetHBitmap(string fileName, int width, int height, ThumbnailOptions options)
|
||||
{
|
||||
IShellItem nativeShellItem;
|
||||
var shellItem2Guid = new Guid(IShellItem2Guid);
|
||||
var retCode = SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out nativeShellItem);
|
||||
var retCode = SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out var nativeShellItem);
|
||||
|
||||
if (retCode != 0)
|
||||
throw Marshal.GetExceptionForHR(retCode);
|
||||
|
||||
var nativeSize = new NativeSize();
|
||||
nativeSize.Width = width;
|
||||
nativeSize.Height = height;
|
||||
var nativeSize = new NativeSize
|
||||
{
|
||||
Width = width,
|
||||
Height = height
|
||||
};
|
||||
|
||||
IntPtr hBitmap;
|
||||
var hr = ((IShellItemImageFactory) nativeShellItem).GetImage(nativeSize, options, out hBitmap);
|
||||
var hr = ((IShellItemImageFactory) nativeShellItem).GetImage(nativeSize, options, out var hBitmap);
|
||||
|
||||
Marshal.ReleaseComObject(nativeShellItem);
|
||||
|
||||
if (hr == HResult.Ok) return hBitmap;
|
||||
|
||||
throw Marshal.GetExceptionForHR((int) hr);
|
||||
|
||||
return hr == HResult.Ok ? hBitmap : IntPtr.Zero;
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
|
||||
Reference in New Issue
Block a user