iPhone:优化石英绘图
我创建了一个 800 像素宽、1200 像素高的 CG 上下文。我在已经转换(缩放、平移和旋转)的上下文上创建了 CGLayer。因此,在某些时候,由于 CGLayer 比上下文大并且已经被平移、旋转等,因此并非该 CGLayer 的所有部分都落入上下文内。请参见下图:
从图片中可以看出,图层的某些部分位于上下文之外区域。当我使用它渲染最终合成时,
CGContextDrawLayerInRect(context, superRect, objectLayer);
它将渲染整个图层,包括上下文之外的那些不必要的部分。
我的问题是:如果我可以让它只绘制上下文中的相关部分,我就可以使其渲染速度更快并节省内存。
有什么办法可以做到这一点吗?
注意:LAYER 包含透明度。
请避免提供不涉及 CGLayers 的解决方案。
提前致谢。
I have created a CG context that is 800 pixels wide and 1200 pixels height. I have created CGLayer over this context that has been transformed (scaled, translated and rotated). So, at some point, as the CGLayer is bigger than the context and has been translated, rotated, etc., not all parts of this CGLayer falls inside the context. See next picture:
As you can see by the picture, some parts of the layer falls outside the context area. When I render the final composition using
CGContextDrawLayerInRect(context, superRect, objectLayer);
it will render the full layer, including those unnecessary parts outside the context.
My problem is: if I can make it draw just the relevant parts inside the context I can make it render fast and save memory.
Is there any way to do that?
NOTE: LAYER contains transparency.
Please refrain from giving solutions that don't involve CGLayers.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 CGContextClip/-ToMask/-ToRect 剪辑上下文。
但我认为简单地将像素“转储”到上下文中实际上比必须计算裁剪边界和“绘制更少”更便宜/更快。
多余的绘图(通常)不会占用额外的内存。
You can clip the context using CGContextClip/-ToMask/-ToRect.
But i think it's actually cheaper/faster to simply 'dump' pixels into a context, than to have to calculate the clipping bounds and 'draw less'.
The surplus drawing doesn't (normally) use-up extra memory.
你能使用CATiledLayer吗?这应该在谷歌地图的方块中延迟加载......
Can you use a CATiledLayer? This should lazy-load in squares ala google maps....