gpt4 book ai didi

ios - 将 CATransform3D 转换为 CIVector 的 CIPerspectiveTransform,替换 UIGetScreenImage

转载 作者:可可西里 更新时间:2023-11-01 06:15:56 26 4
gpt4 key购买 nike

是否可以将 CATransform3D 转换为一组 CIVectors,以便使用 CATransform3D UIImage?

我相信现在终于有可能取代 UIGetScreenImage() 通过遍历 View 层次结构和渲染将 UIView/CALayer 的 3D 变换展平为图像的能力单个图像,然后将 CATransform3D 应用于创建的图像。

我开始使用 GPUImage,它确实接受 CATransform3Ds 以应用于 UIImage,但遗憾的是没有成功。附件是我使用的代码,以及生成的图像的链接。

Screenshot of Simulator

Image Produced

- (UIImage*)iterateLayerHierarchy:(CALayer*)layer
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(layer.frame.size.width,
layer.frame.size.height),
NO,
0.0);


for (CALayer *sublayer in layer.sublayers)
{
UIImage* subImage;

if (sublayer.sublayers.count > 1) {
subImage = [self iterateLayerHierarchy:sublayer];
} else {
subImage = [UIView getImageFromLayer:sublayer];
}
CGRect imageRect;
if (isRetina()) {
imageRect = CGRectMake(sublayer.position.x-subImage.size.width/4,
sublayer.position.y-subImage.size.height/4,
subImage.size.width,
subImage.size.height);
}else{
imageRect = CGRectMake(sublayer.position.x-subImage.size.width/2,
sublayer.position.y-subImage.size.height/2,
subImage.size.width,
subImage.size.height);
}
[subImage drawInRect:imageRect];
//sublayer.hidden = YES;
}

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return img;
}


+ (UIImage*) getImageFromLayer:(CALayer *)layer
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(layer.bounds.size.width,
layer.bounds.size.height),
NO,
0.0);

[layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

if (!CATransform3DEqualToTransform(layer.transform, CATransform3DIdentity))
{
GPUImageTransformFilter *transformFilter = [[GPUImageTransformFilter alloc] init];
transformFilter.transform3D = layer.transform;
img = [transformFilter imageByFilteringImage:img];
}

return img;
}

最佳答案

虽然不是问题的直接答案,但从 iOS 7 开始,不再需要解决这个问题。 “UIGetScreenImage()”实际上已被“drawViewHierarchyInRect:”取代,后者能够同时捕获 OpenGL 层和基于 UIKit 的 View 。

关于ios - 将 CATransform3D 转换为 CIVector 的 CIPerspectiveTransform,替换 UIGetScreenImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16328922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com