首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动画图像屏幕截图

动画图像屏幕截图
EN

Stack Overflow用户
提问于 2015-02-05 13:55:20
回答 2查看 206关注 0票数 2

我有一个图像视图,它每隔几秒钟就会随着卷曲动画而改变。我想拍一段视频,所以我所做的就是,我每秒都会截取屏幕截图,并从中创建视频。但是当图像是动画的时候,我无法截取屏幕截图,那时它会返回图像稳定或没有动画的截图。

我使用下面的代码来截取图像的屏幕截图

代码语言:javascript
复制
{
    CGSize imageSize = [[UIScreen mainScreen] bounds].size;
    if (NULL != UIGraphicsBeginImageContextWithOptions)
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
    else
        UIGraphicsBeginImageContext(imageSize);

    CGContextRef context = UIGraphicsGetCurrentContext();

    // Iterate over every window from back to front
    for (UIWindow *window in [[UIApplication sharedApplication] windows])
    {
        if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
        {
            // -renderInContext: renders in the coordinate space of the layer,
            // so we must first apply the layer's geometry to the graphics context
            CGContextSaveGState(context);
            // Center the context around the window's anchor point
            CGContextTranslateCTM(context, [window center].x, [window center].y);
            // Apply the window's transform about the anchor point
            CGContextConcatCTM(context, [window transform]);
            // Offset by the portion of the bounds left of and above the anchor point
            CGContextTranslateCTM(context,
                                  -[window bounds].size.width * [[window layer] anchorPoint].x,
                                  -[window bounds].size.height * [[window layer] anchorPoint].y);

            // Render the layer hierarchy to the current context
            [[[window layer] presentationLayer] renderInContext:context];

            // Restore the context
            CGContextRestoreGState(context);
        }
    }

    // Retrieve the screenshot image
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;
}

有人知道这件事吗?

提前谢谢。

-Austin

EN

回答 2

Stack Overflow用户

发布于 2015-03-01 03:22:55

我认为你应该使用:

代码语言:javascript
复制
[[[[window contentView] layer] presentationLayer] renderInContext:context];

为了捕获动画的当前状态,而不是源或目标状态

票数 1
EN

Stack Overflow用户

发布于 2017-03-02 16:02:04

根据您的代码,您似乎是在截取屏幕。所以你可以试试这个:

代码语言:javascript
复制
[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]

否则:

代码语言:javascript
复制
[yourAnimatedView.layer.presentationLayer snapshotViewAfterScreenUpdates:NO]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28337101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档