public BooruImage CreateThumbnail(int SideLength, bool Square) { Size size = Bitmap.Size; Size th_size = new Size(SideLength, SideLength); double num = Math.Min((double)th_size.Width / size.Width, (double)th_size.Height / size.Height); Size resultSize = new Size((int)(size.Width * num), (int)(size.Height * num)); if (Square) { //TODO Maybe use floats instead of int division? Point resultPoint = new Point((th_size.Width - resultSize.Width) / 2, (th_size.Height - resultSize.Height) / 2); using (Bitmap th = new Bitmap(th_size.Width, th_size.Height)) { using (Graphics g = CreateAAGraphics(th)) g.DrawImage(Bitmap, resultPoint.X, resultPoint.Y, resultSize.Width, resultSize.Height); return(BooruImage.FromBitmap(th)); } } else { using (Bitmap th = new Bitmap(resultSize.Width, resultSize.Height)) { using (Graphics g = CreateAAGraphics(th)) g.DrawImage(Bitmap, 0f, 0f, resultSize.Width, resultSize.Height); return(BooruImage.FromBitmap(th)); } } }