diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs index b061cf7..014d246 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs @@ -21,7 +21,6 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using LibAPNG; -using QuickLook.Helpers; namespace QuickLook.Plugin.ImageViewer.AnimatedImage { @@ -33,9 +32,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage if (decoder.IsSimplePNG) { - animator.KeyFrames.Add( - new DiscreteObjectKeyFrame(BitmapFrame.Create(new Uri(path)), TimeSpan.Zero)); - animator.Duration = Duration.Forever; + new ImageMagickProvider().GetAnimator(animator, path); return; } @@ -64,7 +61,9 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage private static BitmapSource MakeFrame(IHDRChunk header, Frame rawFrame, Frame previousFrame, BitmapSource previousRenderedFrame) { + var fs = rawFrame.GetBitmapSource(); var visual = new DrawingVisual(); + using (var context = visual.RenderOpen()) { switch (rawFrame.fcTLChunk.DisposeOp) @@ -95,12 +94,12 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage // draw current frame var frameRect = new Rect(rawFrame.fcTLChunk.XOffset, rawFrame.fcTLChunk.YOffset, rawFrame.fcTLChunk.Width, rawFrame.fcTLChunk.Height); - context.DrawImage(rawFrame.GetBitmapSource(), frameRect); - } + context.DrawImage(fs, frameRect); + } var bitmap = new RenderTargetBitmap( header.Width, header.Height, - DpiHelper.DefaultDpi, DpiHelper.DefaultDpi, + Math.Floor(fs.DpiX), Math.Floor(fs.DpiY), PixelFormats.Pbgra32); bitmap.Render(visual); return bitmap; diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/GIFAnimationProvider.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/GIFAnimationProvider.cs index ceffa03..816e2fd 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/GIFAnimationProvider.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/GIFAnimationProvider.cs @@ -20,6 +20,8 @@ using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; +using QuickLook.ExtensionMethods; +using QuickLook.Helpers; namespace QuickLook.Plugin.ImageViewer.AnimatedImage { @@ -85,7 +87,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage } var bitmap = new RenderTargetBitmap( fullImage.PixelWidth, fullImage.PixelHeight, - fullImage.DpiX, fullImage.DpiY, + Math.Floor(fullImage.DpiX), Math.Floor(fullImage.DpiY), PixelFormats.Pbgra32); bitmap.Render(visual); return bitmap; diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/ImageMagickProvider.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/ImageMagickProvider.cs index 6625ace..ace4971 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/ImageMagickProvider.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/ImageMagickProvider.cs @@ -33,6 +33,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage using (var image = new MagickImage(path)) { + image.Density = new Density(Math.Floor(image.Density.X), Math.Floor(image.Density.Y)); image.AutoOrient(); animator.KeyFrames.Add(new DiscreteObjectKeyFrame(image.ToBitmapSource(), TimeSpan.Zero)); diff --git a/QuickLook/ExtensionMethods/BitmapExtensions.cs b/QuickLook/ExtensionMethods/BitmapExtensions.cs index c2bc7c9..492c4c2 100644 --- a/QuickLook/ExtensionMethods/BitmapExtensions.cs +++ b/QuickLook/ExtensionMethods/BitmapExtensions.cs @@ -45,8 +45,8 @@ namespace QuickLook.ExtensionMethods data = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, source.PixelFormat); } - bs = BitmapSource.Create(source.Width, source.Height, source.HorizontalResolution, - source.VerticalResolution, ConvertPixelFormat(source.PixelFormat), null, + bs = BitmapSource.Create(source.Width, source.Height, Math.Floor(source.HorizontalResolution), + Math.Floor(source.VerticalResolution), ConvertPixelFormat(source.PixelFormat), null, data.Scan0, data.Stride * source.Height, data.Stride); source.UnlockBits(data);