diff --git a/Xwt.WPF/Xwt.WPFBackend/ImageHandler.cs b/Xwt.WPF/Xwt.WPFBackend/ImageHandler.cs index 64039a0a..4d63e829 100644 --- a/Xwt.WPF/Xwt.WPFBackend/ImageHandler.cs +++ b/Xwt.WPF/Xwt.WPFBackend/ImageHandler.cs @@ -459,8 +459,15 @@ namespace Xwt.WPFBackend 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)