mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-06 02:06:44 +08:00
Respect screen DPI when obtaining thumbnails
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace QuickLook.Plugin.InfoPanel
|
||||
{
|
||||
internal static class DpiHelper
|
||||
{
|
||||
public enum DeviceCap
|
||||
{
|
||||
/// <summary>
|
||||
/// Logical pixels inch in X
|
||||
/// </summary>
|
||||
LOGPIXELSX = 88,
|
||||
/// <summary>
|
||||
/// Logical pixels inch in Y
|
||||
/// </summary>
|
||||
LOGPIXELSY = 90
|
||||
}
|
||||
|
||||
public const float DEFAULT_DPI = 96;
|
||||
|
||||
public static Dpi GetCurrentDpi()
|
||||
{
|
||||
var g = Graphics.FromHwnd(IntPtr.Zero);
|
||||
var desktop = g.GetHdc();
|
||||
|
||||
var dpi = new Dpi
|
||||
{
|
||||
HorizontalDpi = GetDeviceCaps(desktop, (int) DeviceCap.LOGPIXELSX),
|
||||
VerticalDpi = GetDeviceCaps(desktop, (int) DeviceCap.LOGPIXELSY)
|
||||
};
|
||||
|
||||
return dpi;
|
||||
}
|
||||
|
||||
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
|
||||
public static extern int GetDeviceCaps(IntPtr hDC, int nIndex);
|
||||
}
|
||||
|
||||
internal class Dpi
|
||||
{
|
||||
public float HorizontalDpi { get; set; }
|
||||
public float VerticalDpi { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<ColumnDefinition Width="150" />
|
||||
<ColumnDefinition Width="65*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="image" Grid.Column="0" Height="128" Width="128" Stretch="None" Margin="0,-20,0,0" />
|
||||
<Image x:Name="image" Grid.Column="0" Height="128" Width="128" Stretch="Fill" Margin="0,-20,0,0" />
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70" />
|
||||
|
||||
@@ -26,7 +26,9 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
public void DisplayInfo(string path)
|
||||
{
|
||||
var icon =
|
||||
WindowsThumbnailProvider.GetThumbnail(path, 256, 256,
|
||||
WindowsThumbnailProvider.GetThumbnail(path,
|
||||
(int) (128 * DpiHelper.GetCurrentDpi().HorizontalDpi / DpiHelper.DEFAULT_DPI),
|
||||
(int) (128 * DpiHelper.GetCurrentDpi().VerticalDpi / DpiHelper.DEFAULT_DPI),
|
||||
ThumbnailOptions.ScaleUp);
|
||||
|
||||
image.Source = icon.ToBitmapSource();
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<Compile Include="Controls\VisualTargetPresentationSource.cs" />
|
||||
<Compile Include="ExtensionMethods\TypeExtensions.cs" />
|
||||
<Compile Include="PluginManager.cs" />
|
||||
<Compile Include="Plugin\InfoPanel\DpiHelpers.cs" />
|
||||
<Compile Include="Plugin\InfoPanel\Extensions.cs" />
|
||||
<Compile Include="Plugin\InfoPanel\FileHelper.cs" />
|
||||
<Compile Include="Plugin\InfoPanel\InfoPanel.xaml.cs">
|
||||
|
||||
Reference in New Issue
Block a user