你应该调整它的大小,image.size
这样它就可以将你的大图像缩小到 100k
你可以做一个UIImage
类别
像UIImage(Resize)
+(UIImage*)imageWithImage:(UIImage*)image andWidth:(CGFloat)width andHeight:(CGFloat)height
{
UIGraphicsBeginImageContext( CGSizeMake(width, height));
[image drawInRect:CGRectMake(0,0,width,height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
然后while
循环调整图像大小以适应 <= 100KB
NSData *data = UIImagePNGRepresentation(_yourImage);
while (data.length / 1000 >= 100) {
_yourImage = [UIImage imageWithImage:_yourImage andWidth:image.size.width/2 andHeight:image.size.height/2];
data = UIImagePNGRepresentation(_yourImage);
}
// _yourImage is now reduce the size which is <= 100KB