您的位置:首页 > 产品设计 > UI/UE

iOS - UIView转UIImage

2017-04-13 15:40 1011 查看
此方法失真,模糊

- (UIImage*) imageWithUIView:(UIView*) view{

// 创建一个bitmap的context
// 并把它设置成为当前正在使用的context
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef currnetContext = UIGraphicsGetCurrentContext();
[view.layer renderInContext:currnetContext];
// 从当前context中创建一个改变大小后的图片
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
return image;
}


完美解决失真模糊

-(UIImage*)convertViewToImage:(UIView*)v{
CGSize s = v.bounds.size;
// 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
[v.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: