1.UIView转UIImage(截屏,UIGraphicsBeginImageContextWithOptions函数的使用)
// 需要转成image的view:captureAndSaveView
UIGraphicsBeginImageContextWithOptions(captureAndSaveView.frame.size, NO, 1.0); //NO,YES 控制是否透明
[captureAndSaveView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// 生成后的image
http://liwpk.blog.163.com/blog/static/36326170201210615659749/
2.保存到iOS照片到沙盒
1)保存到iOS照片库需要引入QuartzCore.framework框架,具体代码如下:
.h文件
#import<QuartzCore/QuartzCore.h>
UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIImageView*imageView;
.m文件
UIGraphicsBeginImageCont
[imageView.layerrenderInContext:UIGraphicsGetCurrentCont
UIImage *temp = UIGraphicsGetImageFromCu
UIGraphicsEndImageContex
UIImageWriteToSavedPhoto
2)保存到对应的沙盒目录中,具体代码如下:
NSArray *paths =NSSearchPathForDirectori
NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathCom
BOOL result =[UIImagePNGRepresentation