如何截取整个屏幕截图,无论iOS 7(越狱)中最前面的应用程序,

在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()。 即无法上传到苹果进行审批。 因此,捕获屏幕并保存它的替代方法如下所示。

 - (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]; } 

一些链接可以帮助您如何合法地replaceuigetscreenimage

 UIGraphicsBeginImageContext(self.view.bounds.size); [self.view renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

这个代码可以帮助你得到self.view的屏幕截图,这是iPhone的整个屏幕,不pipe哪个应用在前面。如果你在视图中使用了任何图层,那么图层将不会包含在屏幕截图中为此你必须使用self.view.layer

UIView类有一个名为resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets的方法。

但是我从来没有用过这个方法,所以我不能告诉你更多的信息。

和这篇文章: 捕获UIView作为UIImage显示如何获取返回的UIView到图像。

希望它是有用的。