如何在 C# 中使用 win2D.uwp 在图像上写入文本时旋转文本?

How to rotate text while writing it on image using win2D.uwp in C#?

我正在使用 win2d.uwp nuget 包在图像上添加水印然后保存。像这样

drawingSession.DrawImage(image, 0, 0);
drawingSession.DrawText("Sample Text", x, y, txtColor, canvasTxtFormat);

一切正常。我想在图像上书写时旋转此文本,但我很难在网上找到这方面的帮助。

任何帮助将不胜感激。

您需要使用 Matrix3x2.CreateRotation 来旋转您的文本。例如,以下代码将文本顺时针旋转 90 度 。不要忘记在第二个参数中指定 中心点

drawingSession.Transform *= Matrix3x2.CreateRotation((float)Math.PI / 2, new Vector2(_dimension / 2));
drawingSession.DrawText("Sample Text", x, y, txtColor, canvasTxtFormat);