Created
August 27, 2017 12:13
-
-
Save zirkelc/e93c96238806c4fb06758fc37d690288 to your computer and use it in GitHub Desktop.
This file contains 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 class SquareTransformation : ITransformation | |
{ | |
public string Key => "SquareTransformation"; | |
public IBitmap Transform(IBitmap source) | |
{ | |
double sourceWidth = source.Width; | |
double sourceHeight = source.Height; | |
double desiredWidth = sourceWidth; | |
double desiredHeight = sourceHeight; | |
if (desiredWidth > desiredHeight) | |
{ | |
desiredWidth = desiredHeight; | |
} | |
else if (desiredHeight > desiredWidth) | |
{ | |
desiredHeight = desiredWidth; | |
} | |
else | |
{ | |
return source; | |
} | |
double centerX = sourceWidth / 2; | |
double centerY = sourceHeight / 2; | |
double offsetX = centerX - (desiredWidth / 2); | |
double offsetY = centerY - (desiredHeight / 2); | |
var trans = new CropTransformation(1f, offsetX, offsetY); | |
return trans.Transform(source); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment