Skip to content

Commit

Permalink
Revert "Revert "[WPF] Fix high-DPI image scaling""
Browse files Browse the repository at this point in the history
This reverts commit 67a15a9.

The change introduced in commit db94973
is required for proper HiDPI support. But the scaled sizes are
swapped which causes the regression mentioned in
67a15a9. Fix follows.
  • Loading branch information
sevoku committed Nov 20, 2015
1 parent 9e6a522 commit 8f3b4d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Xwt.WPF/Xwt.WPFBackend/ImageHandler.cs
Expand Up @@ -459,8 +459,15 @@ public void Draw (ApplicationContext actx, SWM.DrawingContext dc, double scaleFa

var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
var bmpImage = f as BitmapSource;
if (bmpImage != null && (bmpImage.PixelHeight != idesc.Size.Height || bmpImage.PixelWidth != idesc.Size.Width))
f = new TransformedBitmap (bmpImage, new ScaleTransform (idesc.Size.Width / bmpImage.PixelWidth, idesc.Size.Height / bmpImage.PixelHeight));

// When an image is a single bitmap that doesn't have the same intrinsic size as the drawing size, dc.DrawImage makes a very poor job of down/up scaling it.
// Thus we handle this manually by using a TransformedBitmap to handle the conversion in a better way when it's needed.

var scaledWidth = idesc.Size.Height * scaleFactor;
var scaledHeight = idesc.Size.Width * scaleFactor;
if (bmpImage != null && (Math.Abs (bmpImage.PixelHeight - scaledHeight) > 0.001 || Math.Abs (bmpImage.PixelWidth - scaledWidth) > 0.001))
f = new TransformedBitmap (bmpImage, new ScaleTransform (scaledWidth / bmpImage.PixelWidth, scaledHeight / bmpImage.PixelHeight));

dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height));

if (idesc.Alpha < 1)
Expand Down

0 comments on commit 8f3b4d0

Please sign in to comment.