绘制使用DrawingContext应用了旋转的矩形 [英] Draw a rectanlge that has a rotation applied using DrawingContext
本文介绍了绘制使用DrawingContext应用了旋转的矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用c#并创建一些线条图。我想创建一个矩形或可能是圆角的矩形绘图,但应用了一个旋转。
我宣布使用:
Hi,
I am using c# and creating some line drawings. I want to create a rectangle or possibly rounded rectangle drawing but with a rotation applied to it.
Im declaring using:
System.Windows.Rect rect = new System.Windows.Rect(startpos.X, startpos.Y, halfsize*2, halfsize * 4);
我现在需要将这个扁平的矩形旋转30度,然后绘制它。
我该怎么做?
我正在使用绘图上下文对象进行渲染。
提前致谢!
I now need to rotate this flat rectangle by say, 30 degrees and THEN draw it.
How do I do this?
I am using the drawing context object to render.
Thanks in advance!
推荐答案
尝试一些这些链接 [ ^ ]。
好的,感谢理查德的操纵。这是代码:
Ok, worked it out thanks to Richard's steer. Here's the code:
// Rectangle to draw.
System.Windows.Rect rect = new System.Windows.Rect(startpos.X, startpos.Y, width, height);
// Set rotation on drawing context.
drawingContext.PushTransform(new Media.RotateTransform(angle, ratio.X, ratio.Y));
// Draw our rectangle.
drawingContext.DrawRectangle(null, myPen, rect);
// Remove transformation for rotation as its no longer needed.
drawingContext.Pop();
这篇关于绘制使用DrawingContext应用了旋转的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文