I have an image in the form of a System.Drawing.Bitmap
and a rectangle in the form of 4 points (Vector2
s which are trivially converted to PointF
s).
I want to use those points to crop out a section of the image. I found this answer which is pretty close to what I want, but I'm not sure how to get the right matrix out of it.
Here's what I've got so far:
protected static Bitmap CropImage(Bitmap src, Vector2[] rect)
{
var width = (rect[1] - rect[0]).Length;
var height = (rect[3] - rect[0]).Length;
var result = new Bitmap(M2.Round(width), M2.Round(height));
using (Graphics g = Graphics.FromImage(result))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
using (Matrix mat = new Matrix())
{
// ????
}
}
return result;
}
How can I get the proper transform matrix out of my rect?