UIGetScreenImage()
函数轻松地截取屏幕截图,但在iOS7中,它已经过时了。现在有没有好的方法来实现这个功能呢?谢谢!补充说明:我需要在任何视图下对整个屏幕进行截图。
UIGetScreenImage()
函数轻松地截取屏幕截图,但在iOS7中,它已经过时了。现在有没有好的方法来实现这个功能呢?谢谢!我遇到了同样的问题,但不知道该如何解决。
我尝试使用IOSurface - IOS Private API - Capture screenshot in background,在一些应用中效果很好,但在游戏中却返回黑屏。
然后我尝试了这个应用程序https://github.com/k06a/UIView-FastScreenshot/blob/master/UIView%2BFastScreenshot.m,它使用私有API,效果很好,但我无法使用theos编译它,总是告诉我“Undefined symbols for architecture armv7: CARenderServerRenderDisplay”。 编辑:我弄清楚了如何使用theos编译它,但返回一个空图像。
https://github.com/coolstar/RecordMyScreen在iOS7上效果很好,但现在它不是开源的,所以我找不到它是如何捕获整个屏幕的。
编辑:RecordMyScreen的代码作为springboard tweak在iOS7上工作,您可以参考这个文件https://github.com/coolstar/RecordMyScreen/blob/master/RecordMyScreen/CSScreenRecorder.m这个方法“- (void)_captureShot:(CMTime)frameTime;”
RecordMyScreen
现在是开源的吗?代码看起来有点老旧。 - Suge替代UIGetScreenImage()的另一种方法
CGImageRef screen = 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];
}
以下是一些链接,可以帮助你合法替换 UIGetScreenImage
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIView类有一个名为resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets的方法。
但我从未使用过这个方法,所以无法告诉您更多信息。
而这篇文章:将UIView捕获为UIImage展示了如何将返回的UIView转换为图像。
希望这对您有用。
[UIWindow mainWindow]
我只能获取到SpringBoard
的视图,而无法获取到最前面的应用程序。 - Suge