iPad上的捕捉视图上下文质量较差

我需要捕获具体的UIView,但结果是在低质量如何解决这个问题,并提高质量?

UIGraphicsBeginImageContext(captureView.bounds.size); [captureView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil); UIGraphicsEndImageContext(); 

我想你需要在视网膜分辨率(960×640或2048×1536)中捕获一个UIView / UIWindow使用UIGraphicsBeginImageContextWithOptions并设置其比例参数0.0f使其以原始分辨率(iPhone 4和更高版本或iPad 3的视网膜)捕捉。

这段代码以自然分辨率捕获你的UIView

 CGRect rect = [captureView bounds]; UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [captureView.layer renderInContext:context]; UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

这个全屏幕(关键窗口)

 UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [keyWindow.layer renderInContext:context]; UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

这将UIImage以95%的质量保存在应用程序的文档文件夹中

 NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage.jpg"]]; [UIImageJPEGRepresentation(capturedImage, 0.95) writeToFile:imagePath atomically:YES]; 

技术问答QA1703拥有非常好的示例代码来制作屏幕截图。

我不知道我是否可以在这里发布,但它可以在链接上。