图片压缩
///原图压缩(压缩完直接nsdata类型保存到本地writeToFile)
- (NSData *)resetSizeOfImageData:(UIImage *)source_image
{
NSData *data;
if (UIImagePNGRepresentation(source_image) == nil) {
data = UIImageJPEGRepresentation( source_image, 1);
}else{
data = UIImagePNGRepresentation(source_image);
}
//先调整分辨率
CGFloat tempHeight;
CGFloat tempWidth;
UIImage *imghh = [UIImage imageWithData:data];
CGSize newSize = CGSizeMake(imghh.size.width, imghh.size.height);
if ( newSize.width<newSize.height){
tempHeight = newSize.height / 1280;
newSize = CGSizeMake(newSize.width/tempHeight, 1280);
}else if (newSize.width>newSize.height){
tempWidth = newSize.width / 1280;
newSize = CGSizeMake(1280, newSize.height/tempWidth);
}
UIGraphicsBeginImageContext(newSize);
[source_image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//调整大小
NSData *imageData;
imageData = UIImageJPEGRepresentation(newImage, 0.3);
return imageData;
}