使用 CGAffineTransform 缩放上下文中的所有点时保留线宽
我在某个坐标系中有一个CGPath
,我想绘制它。这样做涉及到将旧的坐标系缩放到上下文的坐标系上。为此,我使用 CGContextConcatCTM() 来按应有的方式转换所有点。但是,由于这是缩放操作,因此水平/垂直线宽会发生变化。例如,x 方向的比例为 10,y 方向的比例为 1 将导致垂直线的粗细是水平线的 10 倍。有没有一种方法可以保持平移矩阵(例如CGAffineTransform
)的易用性,但同时不能缩放线宽,例如CGPathApplyAffineTransformToPoints
之类的函数?
干杯
法师先生
I have a CGPath
in some coordinate system that I'd like to draw. Doing so involves scaling the old coordinate system onto the Context's one. For that purpose, I use CGContextConcatCTM()
which does transform all the points as it should. But, as it is a scaling operation, the horizontal/vertical line widths get changed to. E.g. a scale of 10 in x-direction, but of 1 in y-direction would lead to vertical lines being 10 times as thick as horizontal ones. Is there a way to keep the ease of use of translation matrices (e.g. CGAffineTransform
) but not scaling line widths at the same time, e.g. a function like CGPathApplyAffineTransformToPoints
?
Cheers
MrMage
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加路径时进行变换,但在描边路径之前删除变换。而不是这样:
这样做:
Do the transform when you add the path, but then remove the transform before you stroke the path. Instead of this:
Do this:
您可以使用 CGPathApply 来迭代路径中的元素。它比单行代码稍微复杂一些,但如果您将其打包在一个简单的辅助函数中,它可能对您有用。这是创建新路径并对其进行转换的一个版本:
要使用它,您将执行以下操作(这是我将放入辅助函数中的部分):
转换后的路径位于
info.path
中观点。You can use
CGPathApply
to iterate through the elements in a path. It's a little bit more complex than just a one-liner but if you package it up in a simple helper function, it might be useful for you. Here is one version that creates a new path and transforms it:To use it you would do (this is the part I would put inside a helper function):
The transformed path is in
info.path
at this point.