ios – 捕获UIView并另存为图像

ios – 捕获UIView并另存为图像,第1张

概述首先我在UI ImageView上添加UILable,然后在屏幕截图UIView之后,图像不正确地捕获UIView Frame我也附加了图像url. 1) Original Image Link :- 2) After Capture the image Link :- 代码: – UIGraphicsBeginImageContext(viewImage.frame.size); [vi 首先我在UI ImageVIEw上添加UILable,然后在屏幕截图UIVIEw之后,图像不正确地捕获UIVIEw Frame我也附加了图像url.

1) Original Image Link :-

2) After Capture the image Link :-

代码: –

UIGraphicsBeginImageContext(vIEwImage.frame.size);    [vIEwImage.layer renderInContext:UIGraphicsGetCurrentContext()];    UIImage *vwImage = UIGraphicsGetimageFromCurrentimageContext();    UIGraphicsEndImageContext();    NSData *data=UIImagePNGRepresentation(vwImage);    NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);    Nsstring *documentsDirectory = [paths objectAtIndex:0];   // Nsstring *imgname = [Nsstring stringWithFormat:imagename];    Nsstring *strPath = [documentsDirectory stringByAppendingPathComponent:imagename];    [data writetofile:strPath atomically:YES];
解决方法 您可以拍摄任何UIVIEw的屏幕截图或捕获任何UIVIEw,并将其保存为具有以下代码的图像.
- (UIImage *)captureVIEw {    //hIDe controls if needed    CGRect rect = [self.vIEw bounds];    UIGraphicsBeginImageContext(rect.size);    CGContextRef context = UIGraphicsGetCurrentContext();    [self.vIEw.layer renderInContext:context];       UIImage *img = UIGraphicsGetimageFromCurrentimageContext();    UIGraphicsEndImageContext();    return img;}
总结

以上是内存溢出为你收集整理的ios – 捕获UIView并另存为图像全部内容,希望文章能够帮你解决ios – 捕获UIView并另存为图像所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存