WPF 矩形变换
我正在尝试使用以下代码将 RotateTransform
应用于 Rect
对象。
Rect transformed = this.Rectangle;
transformed.Transform(this.rotateTransform.Value);
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
context.DrawRectangle(null, new Pen(Brushes.Blue, 2), transformed);
context.Close();
canvas.Children.Add(visual);
但矩形没有旋转。但是,当我将转换推送到 DrawingContext
时(如以下代码所示),矩形会正确转换。
Rect transformed = this.Rectangle;
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
context.PushTransform(this.rotateTransform);
context.DrawRectangle(null, new Pen(Brushes.Blue, 2), transformed);
context.Pop();
context.Close();
canvas.Children.Add(visual);
有没有办法像第一个代码片段中那样使用 Rect.Transform(Matrix) 函数来转换 Rect?
I am trying to apply RotateTransform
to a Rect
object with the following code.
Rect transformed = this.Rectangle;
transformed.Transform(this.rotateTransform.Value);
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
context.DrawRectangle(null, new Pen(Brushes.Blue, 2), transformed);
context.Close();
canvas.Children.Add(visual);
but the rectangle is not rotated. However when I push the transformation to the DrawingContext
, as in the following code, rectangle is transformed correctly.
Rect transformed = this.Rectangle;
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
context.PushTransform(this.rotateTransform);
context.DrawRectangle(null, new Pen(Brushes.Blue, 2), transformed);
context.Pop();
context.Close();
canvas.Children.Add(visual);
Is there a way to transform a Rect as in the first code fragment with Rect.Transform(Matrix)
function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是因为你的旋转不是 90 度的倍数。矩形上的变换会产生与 x 平行的矩形y 轴!
Prabably because your rotation is not multiple of 90deg. Transform on Rect results in rect that it parallel to x & y axis!