2

I have one imageview which is changing on every few seconds with curl animation. I want to take the video of that so for that what I am doing is, I take the screenshots every seconds and create video from that. But I am unable to take the screenshot when image is animating, at that time it will return the screenshot in which image is stable or not animating.

I am using below code to take screenshot of image

{
    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;
}

Does any one have idea about it?

Thanks in advance.

-Austin

4
  • try reducing the period between screen shots to something less
    – Shanti K
    Feb 5, 2015 at 6:01
  • whats the interval that u tried?
    – Shanti K
    Feb 5, 2015 at 6:11
  • I have tried it from 1.0 to 1/30 seconds value...
    – Austin
    Feb 5, 2015 at 6:29
  • care to accept an answer? Mar 29, 2017 at 10:11

2 Answers 2

1

I think you should be using:

[[[[window contentView] layer] presentationLayer] renderInContext:context];

in order to capture the current state of the animation, not the origin or destination states

0

According to your code, you seem to snapshot the screen. So just try this:

[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]

Otherwise:

[yourAnimatedView.layer.presentationLayer snapshotViewAfterScreenUpdates:NO]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.