[WPF] Fix high-DPI image scaling

This should fix issue #401.
This commit is contained in:
Lluis Sanchez Gual 2014-11-29 13:14:49 +01:00
Родитель cf4a66d5f1
Коммит db9497337c
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -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)