本文介绍了iPhone - 抓住CALayers组合的内容是不可能的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在屏幕外的UIView(远大于320x480)上用3D转换了CALayer。

I have a CALayer transformed in 3D on a offscreen UIView (much larger than 320x480).

如何将UIView上看到的内容转储到UIImage?

How do I dump what is seen on this UIView to a UIImage?

注意:我已编辑问题以包含此代码...

这就是我创建图层的方式......

This is how I create the layer...

CGRect area = CGRectMake (0,0,400,600];
vista3D = [[UIView alloc] initWithFrame:area ];

[self.view addSubview:vista3D];
[vista3D release];

transformed = [CALayer layer];
transformed.frame = area;
[vista3D.layer addSublayer:transformed];

CALayer *imageLayer = [CALayer layer];
imageLayer.doubleSided = YES;

imageLayer.frame = area;
imageLayer.transform = CATransform3DMakeRotation(40 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);

imageLayer.contents = (id)myRawImage.CGImage;

[transformed addSublayer:imageLayer];

// Add a perspective effect
CATransform3D initialTransform = transformed.sublayerTransform;
initialTransform.m34 = 1.0 / -500;
transformed.sublayerTransform = initialTransform;

// now the layer is in perspective
// my next step is to "flatten" the composition into a UIImage

UIImage *thisIsTheResult = some magic command

感谢您的帮助!

编辑1:我已尝试过jessecurry解决方案,但它给了我一个没有任何视角的平面图层。

EDIT 1: I have tried jessecurry solution but it gives me a flat layer without any perspective.

编辑2:我发现了一个部分解决方案,但这个解决方案给了我一个大小与屏幕相同的图像,我正在寻找获得更高分辨率的版本,渲染屏幕。

EDIT 2: I discovered a partial solution for this that works, but this solution gives me an image the size of the screen and I was looking for obtaining a higher resolution version, rendering off screen.

推荐答案

在iPhone SDK的范围内,没有办法做到这一点。您可以使用 UIGetScreenImage 获取屏幕内容,或使用 - [CALayer renderInContext:] 将图层绘制到一个 CGContext ,但强制GPU只将一部分图层合成到一个缓冲区中,只能使用私有API和方法来实现。

Within the confines of the iPhone SDK, there is no way to do this. You can grab the contents of the screen with UIGetScreenImage or use -[CALayer renderInContext:] to have a layer draw into a CGContext, but forcing the GPU to composite only a subset of layers into a buffer is something that can only be achieved using private APIs and methods.

这篇关于iPhone - 抓住CALayers组合的内容是不可能的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:06
查看更多