我正在使用UIimagepickerController在屏幕上显示实时相机Feed。但是当我使用以下代码截取屏幕截图时,我会看到黑屏。
-(UIImage *)getScreenShot{
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,
self.view.opaque, [UIScreen mainScreen].scale);
[ipc.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
return image;
}
如何截取屏幕截图?
答案 0 :(得分:0)
尝试编辑
-(void)viewDidLoad
{
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(takeSreenShot) userInfo:nil repeats:NO];
}
-(void)takeSreenShot
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(self.view.bounds.size);
}
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
// grab reference to our window
UIWindow *window = [UIApplication sharedApplication].keyWindow;
// transfer content into our context
[window.layer renderInContext:ctx];
UIImage *screengrab = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// save screengrab to Camera Roll
UIImageWriteToSavedPhotosAlbum(screengrab, nil, nil, nil);
}