如何在放大 CATiledLayer 时在未转换的上下文上绘图?

发布于 2024-09-28 03:50:59 字数 876 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文