在我的应用程序中,我有一个根层,以及许多作为 rootLayer 的子层的图像。我想将 rootLayer 的所有子层展平为一个没有任何子层的层/图像。我认为我应该通过在核心图形上下文中绘制所有子图层来做到这一点,但我不知道该怎么做。
我希望你能理解我,并对我的英语感到抱歉。
来自您自己的 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;
另请注意文档中的警告:
Mac OS X v10.5 的实现
该方法不支持
整个核心动画组成
模型。 QCComposition层,
CAOpenGLLayer 和 QTMovieLayer 层
没有渲染。另外,层
使用 3D 变换的不是
渲染,也不是指定的图层
背景滤镜,滤镜,
compositingFilter,或掩码值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)