Repository navigation
|
Is it possible to rotate a text that is being drawn atop of an image? Can't find a method that accepts an angle for rotation. |
Answered by
tocsoft
Jun 29, 2021
Replies: 1 comment 5 replies
image.Mutate(x => x
.SetDrawingTransform(Matrix3x2Extensions.CreateRotationDegrees(45, new PointF(50, 50))) // set a transform to be applied to all drawing operations
.DrawText("foo bar", font, Color.Black, new PointF(50, 50))); // draw the textThe one gotcha you might hit is the rotation origin of the matrix thus you will most likely need/want to set the point in the This API can be used to apply full matrix transforms to the items being drawn so can also be used for skewing, translating/offsetting, and scaling and as its a transformation matrix you can do them all at once. or alternatively using image.Mutate(x => x
.DrawText(
new DrawingOptions {
Transform = Matrix3x2Extensions.CreateRotationDegrees(45, new PointF(50, 50))
},
"foo bar",
font,
Color.Black,
new PointF(50, 50))); |
5 replies
Answer selected by
ggolda
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

The one gotcha you might hit is the rotation origin of the matrix thus you will most likely need/want to set the point in the
CreateRotationDegrees(angle, point)call to the same as the text drawing point to get the result you expect otherwise we will end up rotating around0,0(top left) and you can end up with text in odd places.This API can be used to apply full matrix transforms to the items being drawn so can also be used…