iOS限制图片的大小
//限制图片的大小为:1M
#define maxImageSize 1024.0
//限制图片大小,传入的maxSize单位是KB
+ (NSData *)reSizeImageData:(UIImage *)sourceImage maxSizeWithKB:(CGFloat)maxSize
{
if (!sourceImage) {
return nil;
}
NSData *imageData = UIImageJPEGRepresentation(sourceImage, 1.0);
CGFloat sizeOriginKB = imageData.length / 1024.0;
CGFloat resizeRate = 0.9;
while (sizeOriginKB > maxSize && resizeRate > 0.1) {
imageData = UIImageJPEGRepresentation(sourceImage, resizeRate);
sizeOriginKB = imageData.length / 1024.0;
resizeRate -= 0.1;
}
return imageData;
}
本文标题:iOS限制图片的大小
本文链接:https://www.haomeiwen.com/subject/immtsttx.html
网友评论