What needs to be done is to add offsets to the alignment of the matrix. In this case, I take one additional length of the rectangle on each side (a total of 9 rectangles) and each time compensating for the matrix.
Note that you must put offset 0 (the original frame) last, otherwise you will get the wrong result.
Also note that if you specify a rectangle that is larger than the rotated image, you will still get empty areas.
public static Bitmap CropRotatedRect(Bitmap source, Rectangle rect, float angle, bool HighQuality) { int[] offsets = { -1, 1, 0 };
To recreate your example:
Bitmap source = new Bitmap("C:\\mjexample.jpg"); Bitmap dest = CropRotatedRect(source, new Rectangle(86, 182, 87, 228), -45, true);
source share