iphone – iPad上的低质量捕获视图上下文
发布时间:2020-12-15 01:50:26 所属栏目:百科 来源:网络整理
导读:我需要捕获特定的UIView,但结果是低质量如何解决这个问题并提高质量? UIGraphicsBeginImageContext(captureView.bounds.size); [captureView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentI
我需要捕获特定的UIView,但结果是低质量如何解决这个问题并提高质量?
UIGraphicsBeginImageContext(captureView.bounds.size); [captureView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIImageWriteToSavedPhotosAlbum(screenshot,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,0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [keyWindow.layer renderInContext:context]; UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 这样可以在应用程序的文档文件夹中以99%的质量保存Upgmage的jpg格式 NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage.jpg"]]; [UIImageJPEGRepresentation(capturedImage,0.95) writeToFile:imagePath atomically:YES]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |