Low quality of capture view context on iPad
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();
- Apple Mach-O Linker (ld) Error Group with Swift 3 & Xcode 9 GM
- Using iOS GameKit's “Bluetooth Bonjour” with other platforms
- Receive remote control events without audio
- why can't I declare a variable like “newVariable” in Obj-C?
- Equivalent of fragment(android) in iOS
- UIBarButtonItem with custom image and no border
2 Solutions Collect From Internet About “Low quality of capture view context on iPad”
I guess you need a capture a UIView/UIWindow in retina resolution (960×640 or 2048×1536) Using UIGraphicsBeginImageContextWithOptions and set its scale parameter 0.0f makes it capture in native resolution (retina for iPhone 4 and later or iPad 3).
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();
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];
Technical Q&A QA1703 holds a really nice sample code to make a screenshot.
I don’t know if i can post it here but it’s available on the link.
- Swift http request use urlSession
- How to create several UIButtons along a path/BezierCurve?
- Check whether Swift object is an instance of a given metatype
- file was built for archive which is not the architecture being linked (i386)
- Uniquely identifying an iOS user
- Constants in Objective-C
- Code Sign Error on macOS Sierra, Xcode 8
- How to detect total available/free disk space on the iPhone/iPad device?
- iOS: setting Exclusive Touch to all buttons in a view
- How to use Document Provider Extension?
- Rename a class in Xcode: Refactor… is grayed out (disabled). Why?
- IOS: problem with resize a UIImage
- xcode commit missing file or directory
- Converting jpeg to bitmap in ios using objective c?
- Can a subclass override a function and make more restrictive return?