将CALayer子图层平铺到一个图层中 [英] Flatten CALayer sublayers into one layer
问题描述
在我的应用程序中,我有一个根层,许多图像是rootLayer的子图层。我想把rootLayer的所有子图层变成一个图层/图像,没有任何子图层。我想我应该通过绘制核心图形上下文中的所有子图层,但我不知道如何做到这一点。
In my app I have one root layer, and many images which are sublayers of rootLayer. I'd like to flatten all the sublayers of rootLayer into one layer/image, that don't have any sublayers. I think I should do this by drawing all sublayers in core graphics context, but I don't know how to do that.
我希望你能理解我,对于我的英语。
I hope you'll understand me, and sorry for my English.
推荐答案
从您自己的Mac OS X示例:
From your own example for Mac OS X:
CGContextRef myBitmapContext = MyCreateBitmapContext(800,600);
[rootLayer renderInContext:myBitmapContext];
CGImageRef myImage = CGBitmapContextCreateImage(myBitmapContext);
rootLayer.contents = (id) myImage;
rootLayer.sublayers = nil;
CGImageRelease(myImage);
iOS:
UIGraphicsBeginImageContextWithOptions(rootLayer.bounds.size, NO, 0.0);
[rootLayer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
rootLayer.contents = (id) layerImage.CGImage;
rootLayer.sublayers = nil;
另请注意文档中的注意事项:
Also note the caveat in the docs:
的Mac OS X v10.5实现此方法不支持
整个Core Animation组合
模型。不渲染QCCompositionLayer,
CAOpenGLLayer和QTMovieLayer图层
。此外,使用3D变换的图层
不是
呈现的,也不是指定
backgroundFilters,filters,
compositingFilter或掩码值的图层。
The Mac OS X v10.5 implementation of this method does not support the entire Core Animation composition model. QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer layers are not rendered. Additionally, layers that use 3D transforms are not rendered, nor are layers that specify backgroundFilters, filters, compositingFilter, or a mask values.
这篇关于将CALayer子图层平铺到一个图层中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!