方法一:
//CGSize size區域大小,BOOL opaque,是否為非透明,如果需要顯示半透明效果,需要傳NO,否則傳YES,第三個參數就是屏幕密度([UIScreen mainScreen].scale? 得到設備的分辨率)
UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//保存照片
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
方法二:
//創建一個基于位圖的圖形上下文并指定大小為CGSizeMake(200,400)
UIGraphicsBeginImageContext(CGSizeMake(200,400));
//renderInContext 呈現接受者及其子范圍到指定的上下文
[self.view.layerrenderInContext:UIGraphicsGetCurrentContext()];
//返回一個基于當前圖形上下文的圖片
UIImage *aImage =UIGraphicsGetImageFromCurrentImageContext();
//移除棧頂的基于當前位圖的圖形上下文
UIGraphicsEndImageContext();
//以png格式返回指定圖片的數據
imageData = UIImagePNGRepresentation(aImage);
//保存照片
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
方法一的到的可以設置分辨率,所以相對方法二而言,方法一可以得到清晰的圖片