【发布时间】:2015-02-05 05:55:19
【问题描述】:
我有一个图像视图,它每隔几秒就会用 curl 动画改变。我想拍摄那个视频,所以我正在做的是,我每秒截取屏幕截图并从中创建视频。 但是我无法在图像动画时截取屏幕截图,此时它会返回图像稳定或没有动画的屏幕截图。
我正在使用下面的代码来截取图像
{
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;
}
有人知道吗?
提前致谢。
-奥斯汀
【问题讨论】:
-
尝试缩短屏幕截图之间的时间间隔
-
你尝试的时间间隔是多少?
-
我已经尝试过从 1.0 到 1/30 秒的值...
-
愿意接受答案吗?
标签: ios iphone cgcontext objective-c-2.0 uigraphicscontext