Sitelet https://github.com/SixLabors/ImageSharp/issues/2753
Skip to content

Rotation of AffineTransform seems to offset the image by 1 pixel #2753

Description

@Socolin

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.4

Other ImageSharp packages and versions

ImageSharp.Drawing 2.1.3

Environment (Operating system, version and so on)

Ubuntu 22.04, AMD Ryzen 9 7950X

.NET Framework version

8.0

Description

When using the rotation through the AffineTransformBuilder the result is not the same as the .Rotate() there seems to be 1 pixel offset.

Here the sample code of what I would expect

using (var img = new Image<Rgba32>(100, 100, Color.DimGray))
{
	img.Mutate(c => c
		.Rotate(180)
		.Fill(Color.Aqua, new RectangleF(49, 49, 2, 2))
	);
	img.Save("rotation-rotate.png");
}

Which give this result:
image

Steps to Reproduce

When I do the same with the .Transform() I'm getting this:

using (var img = new Image<Rgb24>(100, 100, Color.DimGray))
{
	img.Mutate(c => c
		.Transform(new  AffineTransformBuilder().AppendRotationDegrees(180))
		.Fill(Color.Aqua, new RectangleF(49, 49, 2, 2))
	);
	img.Save("rotation-center.png");
}

image
image

Another example with non centered rotation

for (int i = 0; i <= 10; i++)
{

	using (var img = new Image<Rgba32>(100, 100, Color.DimGray))
	{
		img.Mutate(c => c
			.Transform(new  AffineTransformBuilder().AppendTranslation(new Vector2(100, 100)))
			.Transform(new  AffineTransformBuilder().AppendRotationDegrees(i * 18, new Vector2(100, 100)))
			.Fill(Color.Aqua, new RectangleF(99, 99, 2, 2))
		);
		img.Save($"rotation-{i}.png");
	}
}

image
image

The rotation seems to be centered 1 pixel too much toward the bottom-right

Images

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions