UIView 转 UIImage

2017-07-11  本文已影响14人  坤哥爱卿

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

//创建一个bitmap的context

//并把它设置成为当前正在使用的context

UIGraphicsBeginImageContext(CGSizeMake(view.bounds.size.width, view.bounds.size.height));

CGContextRefcurrnetContext =UIGraphicsGetCurrentContext();

[view.layerrenderInContext:currnetContext];

//从当前context中创建一个改变大小后的图片

UIImage* image =UIGraphicsGetImageFromCurrentImageContext();

//使当前的context出堆栈

UIGraphicsEndImageContext();

returnimage;

}

上一篇 下一篇

猜你喜欢

热点阅读