Created
May 31, 2013 13:26
-
-
Save jmcd/5684950 to your computer and use it in GitHub Desktop.
Make a square image
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
private Image MakeSquareImage(Image source, int targetLength) | |
{ | |
var sourceBitmap = new Bitmap(source); | |
var sourceLength = Math.Min(source.Size.Height, source.Size.Width); | |
var cropRect = new Rectangle((source.Size.Width - sourceLength)/2, (source.Size.Height - sourceLength)/2, sourceLength, sourceLength); | |
var squaredSource = sourceBitmap.Clone(cropRect, sourceBitmap.PixelFormat); | |
var result = new Bitmap(squaredSource, new Size(targetLength, targetLength)); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment