1
2
3
4
5
6
7
8
|
-(UIImage*)convertViewToImage:(UIView*)v{
CGSize
s = v.bounds.size;
UIGraphicsBeginImageContext(s);
[v.layer
renderInContext:UIGraphicsGetCurrentContext()];
UIImage*image
= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return
image; } |
1
2
3
4
5
6
7
8
|
-(UIImage*)convertViewToImage:(UIView*)v{
CGSize
s = v.bounds.size;
UIGraphicsBeginImageContextWithOptions(s,
NO ,
v.layer.contentsScale);
[v.layer
renderInContext:UIGraphicsGetCurrentContext()];
UIImage*image
= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return
image; } |
1
2
3
4
5
6
7
8
9
|
-(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; } |
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/q644419002/article/details/47086377