简体   繁体   English

iPhone:优化的石英制图

[英]iPhone: optimized drawing in quartz

I have created a CG context that is 800 pixels wide and 1200 pixels height. 我创建了一个CG上下文,其宽度为800像素,高度为1200像素。 I have created CGLayer over this context that has been transformed (scaled, translated and rotated). 我在已转换(缩放,平移和旋转)的上下文中创建了CGLayer。 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. 因此,在某些时候,由于CGLayer大于上下文并且已被平移,旋转等,因此,并非CGLayer的所有部分都位于上下文内。 See next picture: 见下图:

layer and context 层和上下文

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. 注意:LAYER包含透明度。

Please refrain from giving solutions that don't involve CGLayers. 请不要提供不涉及CGLayers的解决方案。

thanks in advance. 提前致谢。

You can clip the context using CGContextClip/-ToMask/-ToRect. 您可以使用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. 多余的绘图不会(通常)耗尽额外的内存。

Can you use a CATiledLayer? 您可以使用CATiledLayer吗? This should lazy-load in squares ala google maps.... 这应该在正方形ala Google地图中延迟加载。

+(Class)layerClass
{
return [CATiledLayer class];
}


-(id)init {
   CATiledLayer *tiledLayer = (CATiledLayer *) self.layer;
   tiledLayer.tileSize = CGSize(x,x);
   tiledLayer.levelsOfDetail = y;
   tiledLayer.levelsOfDetailBias = z;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM