private Bitmap resizeIfNecessary(Bitmap bmpOriginal)
{
if (Graphics.NPOTAllowed)
return bmpOriginal;
else
{
Log.i("This hardware does not support non power-of-two textures - hax will be applied.");
lock (resizeResultDictionary)
{
// Aye, we do cache 'em...
if (resizeResultDictionary.Keys.Contains(bmpOriginal))
return resizeResultDictionary[bmpOriginal];
else
{
int referencesize = (bmpOriginal.Width > bmpOriginal.Height
? bmpOriginal.Width : bmpOriginal.Height);
int newsize = 2;
// Find next bigger POT size.
for (int i = 1; newsize < referencesize; i++)
newsize = (int)Math.Round(Math.Pow(2, i));
potTextureSize = newsize;
// Resize bitmap, and return the result!
Bitmap bmpResult = new Bitmap(newsize, newsize);
System.Drawing.Graphics gRes = System.Drawing.Graphics.FromImage(bmpResult);
gRes.DrawImage(bmpOriginal, 0, 0);
gRes.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
gRes.Dispose();
resizeResultDictionary.Add(bmpOriginal, bmpResult);
return bmpResult;
}
}
}
}