标签:
//图片大小缩放
+ (UIImage *) scaleImage:(UIImage *)image toSize:(CGSize)size {
UIGraphicsBeginImageContext(size); //size 为CGSize类型,即你所需要的图片尺寸
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage; //返回的就是已经改变的图片
}
//压缩图片,并返回成数据格式的
+ (NSData *) zipImage:(UIImage *)img rate:(CGFloat)rate{
NSData *retImg = UIImageJPEGRepresentation(img, 0.5);
if (retImg==nil) {
retImg = UIImagePNGRepresentation(img);
}
return retImg;
}
标签:
原文地址:http://www.cnblogs.com/TheYouth/p/4981349.html