private Size CalculateImageSize(int sideVal, fixedSize fixedSide) { Size mySize = new Size(); float ratioCur = ((float)_original.Width / (float)_original.Height); switch (fixedSide) { case fixedSize.Height: mySize.Height = sideVal; if (_original.Height > _original.Width) { mySize.Width = Convert.ToInt32(sideVal * ratioCur); } else { mySize.Width = Convert.ToInt32(sideVal * ratioCur); } break; case fixedSize.Width: mySize.Width = sideVal; if (_original.Height > _original.Width) { mySize.Height = Convert.ToInt32(sideVal / ratioCur); } else { mySize.Height = Convert.ToInt32(sideVal / ratioCur); } break; } return(mySize); }
public Image resize(int sideVal, fixedSize fixedSide) { Size newSize = CalculateImageSize(sideVal, fixedSide); Bitmap TargetBitmap = new Bitmap(_original, newSize); using (Graphics TargetGraphic = Graphics.FromImage(TargetBitmap)) { TargetGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic; TargetGraphic.SmoothingMode = SmoothingMode.HighQuality; TargetGraphic.DrawImage(_original, new Rectangle(0, 0, newSize.Width, newSize.Height), 0, 0, _original.Width, _original.Height, GraphicsUnit.Pixel); } return(TargetBitmap); }