[英]How to take screenshot for the entire screen no matter which app is at front most in iOS 7(Jailbroken)
在iOS7之前,我使用UIGetScreenImage()
函数轻松获取截图,但在iOS7中,它已被弃用,现在有什么好方法可以存档吗?谢谢!
另外:我需要在任何视图中截取整个屏幕的截图
我遇到了同样的问题,但没有想法如何解决它。
我尝试了IOSurface - IOS Private API - 在后台截取屏幕截图,在某些应用程序中运行良好但在游戏中返回黑屏。
然后我尝试了这个应用程序https://github.com/k06a/UIView-FastScreenshot/blob/master/UIView%2BFastScreenshot.m ,使用私有api很好,但我无法使用theos编译它,总是告诉我“架构armv7的未定义符号:CARenderServerRenderDisplay“。 编辑:我想出了如何使用theos编译它,但返回是空图像。
此外, https: //github.com/coolstar/RecordMyScreen在iOS7中运行良好,但它现在不是开源的,所以我无法找到它如何捕获整个屏幕。
编辑:RecordMyScreen的代码适用于iOS7作为跳板调整 ,你可以参考这个文件https://github.com/coolstar/RecordMyScreen/blob/master/RecordMyScreen/CSScreenRecorder.m这个方法“ - (void)_captureShot:(CMTime )frameTime的;”
替换UIGetScreenImage()的替代方法
CGImageRef screen = UIGetScreenImage();
上面的代码是捕获屏幕的一行代码,但Apple没有为公共应用程序打开上面的API UIGetScreenImage()。 即无法上传到Apple批准。 因此,捕获屏幕并保存它的替代方法如下所示。
- (void)captureAndSaveImage
{
// Capture screen here... and cut the appropriate size for saving and uploading
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// crop the area you want
CGRect rect;
rect = CGRectMake(0, 10, 300, 300); // whatever you want
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *img = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
imageView.image = img; // show cropped image on the ImageView
}
// this is option to alert the image saving status
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
一些链接可以帮助您如何合法地替换uigetscreenimage
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
此代码可以帮助您获得self.view的截图这是整个iPhone的屏幕的问题上没有哪个应用在front.If你已经使用在视图中的任何层,则层将不会被包含在截图为此你必须使用self.view.layer 。
UIView类有一个名为:resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets的方法。
但我从来没有使用过这种方法,因此我无法告诉你更多关于它的信息。
这篇文章: 捕获UIView作为UIImage显示了如何将返回的UIView转换为图像。
希望它有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.