- (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;
}