rad*_*dex 2 cocoa core-animation core-graphics objective-c
在我的应用程序中,我有一个根层,以及许多图像是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);
Run Code Online (Sandbox Code Playgroud)
iOS版:
UIGraphicsBeginImageContextWithOptions(rootLayer.bounds.size, NO, 0.0);
[rootLayer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
rootLayer.contents = (id) layerImage.CGImage;
rootLayer.sublayers = nil;
Run Code Online (Sandbox Code Playgroud)
另请注意文档中的警告:
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.
| 归档时间: |
|
| 查看次数: |
3530 次 |
| 最近记录: |