iOS 图片压缩

有时候从App上传图片给后台,由于图片较大, 需要将图片压缩一下。

压缩的时候注意有的方案会卡线程,耗时。

这里有个方案:不耗时,不卡线程

-(UIImage *)makeThumbnailFromImage:(UIImage *)srcImage scale:(double)imageScale{
    
    UIImage *thumbail = nil;
    CGSize imageSize = CGSizeMake(srcImage.size.width*imageScale, srcImage.size.height*imageScale);
    
    if (srcImage.size.width != imageSize.width || srcImage.size.height != imageSize.height) {
        UIGraphicsBeginImageContext(imageSize);
        CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
        
        [srcImage drawInRect:imageRect];
        thumbail = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
    }
    else{
        thumbail = srcImage;
    }
    return thumbail;
    
}

参考自:https://www.cnblogs.com/ChouDanDan/p/5038396.html#commentform

iOS 图片压缩

上一篇:Vue:Axios异步通信


下一篇:【转】Android Monkey 命令行可用的全部选项