Fixed scaling

This commit is contained in:
Flamefire committed 2013-04-18 12:37:25 +02:00
1 parent eb71c1158e
commit 2dc2ac5c37
1 file changed
+21 -15
+21 -15
View File
@@ -919,29 +919,35 @@ namespace Vocaluxe.Lib.Draw
int w = bmp.Width; int w = bmp.Width;
int h = bmp.Height; int h = bmp.Height;
float ratio = (float)w / h;
int newW = w;
int newH = h;
if (w > maxSize && w > h) if (w > maxSize && w > h)
{ newW = maxSize;
h = (int)Math.Round((float)maxSize / bmp.Width * bmp.Height); else if (h > maxSize)
w = maxSize; newH = maxSize;
} else if (w > h)
newW = (int)_CheckForNextPowerOf2(w);
if (h > maxSize) else
{ newH = (int)_CheckForNextPowerOf2(h);
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);
Bitmap bmp2 = null; Bitmap bmp2 = null;
byte[] data; byte[] data;
try 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 //Create a new Bitmap with the new sizes
bmp2 = new Bitmap(w, h); bmp2 = new Bitmap(w, h);
//Scale the texture //Scale the texture