From 2dc2ac5c3768d37ecf48943edda74a7448c539a5 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Thu, 18 Apr 2013 12:15:30 +0200 Subject: [PATCH] Fixed scaling --- Vocaluxe/Lib/Draw/CDirect3D.cs | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 057f1ff7..c27c7e76 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -919,29 +919,35 @@ namespace Vocaluxe.Lib.Draw int w = bmp.Width; int h = bmp.Height; + float ratio = (float)w / h; + int newW = w; + int newH = h; if (w > maxSize && w > h) - { - h = (int)Math.Round((float)maxSize / bmp.Width * bmp.Height); - w = maxSize; - } - - if (h > maxSize) - { - w = (int)Math.Round((float)maxSize / bmp.Height * bmp.Width); - h = maxSize; - } - - //Older graphics card can only handle textures with sizes being powers of two - w = (int)_CheckForNextPowerOf2(w); - h = (int)_CheckForNextPowerOf2(h); + newW = maxSize; + else if (h > maxSize) + newH = maxSize; + else if (w > h) + newW = (int)_CheckForNextPowerOf2(w); + else + newH = (int)_CheckForNextPowerOf2(h); Bitmap bmp2 = null; byte[] data; try { - if (w != bmp.Width || h != bmp.Height) + if (w != newW || h != newH) { + if (w != newW) + { + w = newW; + h = (int)Math.Round(w / ratio); + } + else + { + h = newH; + w = (int)Math.Round(h * ratio); + } //Create a new Bitmap with the new sizes bmp2 = new Bitmap(w, h); //Scale the texture