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
此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935.
我的gitHub: (学习代码都在gitHub)
https://github.com/nwgdegitHub/

浙公网安备 33010602011771号