Created
April 9, 2012 17:03
-
-
Save rodolfofadino/2344761 to your computer and use it in GitHub Desktop.
PadImage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static System.Drawing.Image PadImage(System.Drawing.Image originalImage) | |
{ | |
int largestDimension = Math.Max(originalImage.Height, originalImage.Width); | |
int h = originalImage.Size.Height; | |
int w = originalImage.Size.Width; | |
int final = 0; | |
if (w >= h) | |
final = h; | |
else | |
final = w; | |
Size squareSize = new Size(final, final); | |
Bitmap squareImage = new Bitmap(squareSize.Width, squareSize.Height); | |
using (Graphics graphics = Graphics.FromImage(squareImage)) | |
{ | |
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; | |
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; | |
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; | |
graphics.DrawImage(originalImage, (squareSize.Width / 2) - (originalImage.Width / 2), (squareSize.Height / 2) - (originalImage.Height / 2), originalImage.Width, originalImage.Height); | |
} | |
return squareImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment