UIView 转 UIImage

来源:互联网 发布:小米防蓝光眼镜知乎 编辑:程序博客网 时间:2024/05/16 18:56

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

}


原创粉丝点击