iPad上的低质量捕获视图上下文 [英] Low quality of capture view context on iPad
问题描述
我需要捕获特定的UIView,但结果是低质量如何解决这个问题并提高质量?
I need capture specific UIView , but the result is in low quality how can fix this and increase the quality ?
UIGraphicsBeginImageContext(captureView.bounds.size);
[captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
UIGraphicsEndImageContext();
推荐答案
我想你需要捕获一个UIView / UIWindow in视网膜分辨率(960x640或2048x1536)使用UIGraphicsBeginImageContextWithOptions并设置其缩放参数0.0f使其以原始分辨率捕获(适用于iPhone 4及更高版本或iPad 3的视网膜)。
I guess you need a capture a UIView/UIWindow in retina resolution (960x640 or 2048x1536) Using UIGraphicsBeginImageContextWithOptions and set its scale parameter 0.0f makes it capture in native resolution (retina for iPhone 4 and later or iPad 3).
代码以原始分辨率捕获你的UIView
This code capture your UIView in native resolution
CGRect rect = [captureView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[captureView.layer renderInContext:context];
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这个全屏相同(关键窗口)
This one does the same for full screen (key window)
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();
这可以在应用程序的文档文件夹中以99%的质量保存Upgmage格式
This saves the UIImage in jpg format with 95% quality in the app's document folder
NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage.jpg"]];
[UIImageJPEGRepresentation(capturedImage, 0.95) writeToFile:imagePath atomically:YES];
这篇关于iPad上的低质量捕获视图上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!