“renderInContext:”和 CATransform3D

问题描述 投票:0回答:3

我有一个视图,里面有多个视图,还有一个图像演示(又名“封面流”)......而且我需要以编程方式截取屏幕截图!

因为文档说“renderInContext:”不会渲染 3d 动画:

“重要提示此方法的 Mac OS X v10.5 实现不支持整个核心动画合成模型。QCCompositionLayer、CAOpenGLLayer 和 QTMovieLayer 图层不会渲染。此外,不会渲染使用 3D 变换的图层,也不会渲染使用 3D 变换的图层。指定背景过滤器、过滤器、合成过滤器或遮罩值。Mac OS X 的未来版本可能会添加对渲染这些图层和属性的支持。”

来源:https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html

我已经搜索了很多,我的“最佳”解决方案(一点也不好)是创建我自己的CGContext并将所有CG动画记录到其中。但我真的不想这样做,因为我需要重新编写大部分动画代码,这对内存来说非常昂贵......我找到了其他解决方案(其中一些是不可修改的),例如使用 openGL 或通过捕获AVSessions,但没有人可以帮助我......

我有什么选择?有这个问题吗?

graphics core-graphics catransform3d
3个回答
0
投票

你真的尝试过吗?我目前正在开发一个具有多个 3D 变换的项目,当我尝试以编程方式制作此屏幕截图时,它工作得很好:) 这是我使用的代码:

-(UIImage *)getScreenshot
{
    CGFloat scale = 1.0;
    if([[UIScreen mainScreen]respondsToSelector:@selector(scale)])
    {        
        CGFloat tmp = [[UIScreen mainScreen]scale];
        if (tmp > 1.5)
        {
            scale = 2.0;    
        }
    }      
    if(scale > 1.5)
    {
        UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, scale);
    } 
    else
    {
        UIGraphicsBeginImageContext(self.frame.size);
    }    
    //SELF HERE IS A UIVIEW
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];    
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return screenshot;
}

0
投票

我让它与协议一起工作......我正在所有进行 3D 转换的

UIViews
类中实现一个协议。因此,当我请求屏幕截图时,它会对所有子视图进行屏幕截图,并生成一个 UIImage。对于大量视图来说不太好,但我正在几个视图中进行操作。

#pragma mark - Protocol implementation 'TDITransitionCustomTransform'

//Conforms to "TDITransitionCustomTransform" protocol, return currrent image view state , by current layer

- (UIImage*)imageForCurrentState {

//Make print

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);

[self.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

//return printed image

return screenShot;

}

我认为它现在可能有效,因为我正在转换后的视图层中进行渲染,该视图层已自行转换... 它不起作用,因为“renderInContext:”没有获得它的子视图层,可能吗?

任何对此解决方案感兴趣的人都可以在here找到。在苹果开发者论坛中。

这可能是一个功能错误,或者只是不是为此目的而设计的......


0
投票

也许你可以使用 Core Graphic 而不是 CATransform3DMakeRotation :)

CGAffineTransform flip = CGAffineTransformMakeScale(1.0, -1.0);

这会对 renderInContext 产生影响

© www.soinside.com 2019 - 2024. All rights reserved.