Skip to content

Instantly share code, notes, and snippets.

@zirkelc
Created August 27, 2017 12:13
Show Gist options
  • Save zirkelc/e93c96238806c4fb06758fc37d690288 to your computer and use it in GitHub Desktop.
Save zirkelc/e93c96238806c4fb06758fc37d690288 to your computer and use it in GitHub Desktop.
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