如何在放大 CATiledLayer 时在未转换的上下文上绘图?
我正在使用 CATiledLayer 来实现数据可视化。默认情况下,drawLayer 函数获取转置和缩放的上下文,这允许绘图代码与所请求的缩放级别和图块无关。
但是,我想使用缩放功能来更改数据的水平范围,而不发生实际缩放。
到目前为止,我得到了这段代码:
(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context {
/* retrieve the transformation matrix from the context. */
CGAffineTransform contextTrans = CGContextGetCTM(context);
/* Scale the context back, so all items will still have the same size */
CGContextScaleCTM(context, 1.0/contextTrans.a, 1.0/contextTrans.d);
<.. loop through all datapoints ..> {
/* Transpose the point-centers to the new zoomed context */
xCoord = xCoord * contextTrans.a;
yCoord = yCoord * contextTrans.d;
}
<.. drawing code ..>
}
这可行,但缺点是放大时元素会变得模糊。(仅为每个屏幕像素渲染 1/zoomfactor 像素)
有什么方法可以防止这种模糊的发生吗?
或者,有什么方法可以绘制未转换的上下文,而不是转置的上下文?
I'm using a CATiledLayer for the visualisation of data. By default the drawLayer function gets a transposed and scaled context, which allow the drawing code to be agnostic of the zoom-level and the tile that's being requested.
However, I would like to use the zoom functionality to change the horizontal range of the data, without actual zooming occuring.
So far, I got this code:
(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context {
/* retrieve the transformation matrix from the context. */
CGAffineTransform contextTrans = CGContextGetCTM(context);
/* Scale the context back, so all items will still have the same size */
CGContextScaleCTM(context, 1.0/contextTrans.a, 1.0/contextTrans.d);
<.. loop through all datapoints ..> {
/* Transpose the point-centers to the new zoomed context */
xCoord = xCoord * contextTrans.a;
yCoord = yCoord * contextTrans.d;
}
<.. drawing code ..>
}
This works, but has the disadvantage that the elements get blurry when zoomed in. (only 1/zoomfactor pixels are rendered for each on-screen pixel)
Any methods to prevent this blurryness from happening?
Alternatively, is there any way to draw to the non-transformed context, rather than the transposed one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论