UIImage转换成UIView

#import <QuartzCore/QuartzCore.h>//记住要加上这个头文件!!!

- (UIImage*)convertViewToUIImage:(UIView*)v
{
    UIGraphicsBeginImageContext(v.bounds.size);
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    [v.layer renderInContext:currentContext];
      // 从当前context中创建一个改变大小后的图片  
    UIImage  *image = UIGraphicsGetImageFromCurrentImageContext();
        // 使当前的context出堆栈  
    UIGraphicsEndImageContext();
    return image;
}

使用方法:

UIView *view =[[UIView alloc]init];

UIImage *image = [self convertViewToUIImage:view];

 

 
posted @ 2012-12-01 17:10  小白猪jianjian  阅读(1112)  评论(0编辑  收藏  举报