保存图片到沙盒中:
hasSuffix以****为结尾
if ([imgPath hasSuffix:@".jpg"] || [imgPath hasSuffix:@".JPG"]) {
//默认一般转换为jpeg格式,降低内存占有量
[UIImageJPEGRepresentation(image, 1.0) writeToFile:savePath atomically:YES];
}else {
[UIImagePNGRepresentation(image) writeToFile:savePath atomically:YES];
}
重绘图片 一般用于将大图片压缩为小图片
#pragma mark
图片压缩
-(UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
//
创建一个bitmap的context
//
并把它设置成为当前正在使用的context
UIGraphicsBeginImageContext(size);
//
绘制改变大小的图片
[img drawInRect:CGRectMake(0, 0, size.width, size.height)];
//
从当前context中创建一个改变大小后的图片
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
//
使当前的context出堆栈
UIGraphicsEndImageContext();
//
返回新的改变大小后的图片
return scaledImage;
}