I'm "translating" a program written in C # for Android, and I had a problem while performing the rotation of an image. The code works normally, but returns an image of a different size than the original, I understand why the new image has a different size, but how can I make that image come back the same size as the original, leaving out the image's edges? / p>
The rotated image is not displayed to the user, it is only used internally to perform some calculations.
public static Bitmap Rotate(Bitmap source, int anchorX, int anchorY, float angle)
{
Matrix matrix = new Matrix();
matrix.postRotate(angle, anchorX, anchorY);
return = Bitmap.createBitmap(source, 0, 0, source.getWidth(),
source.getHeight(), matrix, true);
}
Original C # :
public static Bitmap Rotate(Bitmap image, Point offset, float angle)
{
if (image == null) return null;
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
Graphics g = Graphics.FromImage(rotatedBmp);
g.TranslateTransform(offset.X, offset.Y);
g.RotateTransform(angle);
g.TranslateTransform(-offset.X, -offset.Y);
g.DrawImage(image, new PointF(0, 0));
return rotatedBmp;
}