iphone – iPad上的低质量捕获视图上下文

iphone – iPad上的低质量捕获视图上下文,第1张

概述我需要捕获特定的UIView,但结果是低质量如何解决这个问题并提高质量? UIGraphicsBeginImageContext(captureView.bounds.size); [captureView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGe 我需要捕获特定的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];
总结

以上是内存溢出为你收集整理的iphone – iPad上的低质量捕获视图上下文全部内容,希望文章能够帮你解决iphone – iPad上的低质量捕获视图上下文所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1068679.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存