需求是压到 100kb 以下
UIImageJPEGRepresentation 这个无法满足需求
UIImageJPEGRepresentation 这个无法满足需求
|
haosxianrSep 6, 2015 via iPhone
1
用 CoreImage 把图片尺寸调低试试
|
|
2
这种需求,直接打回去不给做。不谈图片分辨率只要求文件大小的压缩都是耍流氓。
|
|
fghfjujiberSep 6, 2015
4
CGFloat compression = 0.9f;
CGFloat maxCompression = 0.1f; int maxFileSize = 250*1024; NSData *imageData = UIImageJPEGRepresentation (yourImage, compression ); while ([imageData length] > maxFileSize && compression > maxCompression ) { compression -= 0.1; imageData = UIImageJPEGRepresentation (yourImage, compression ); } ref: http://stackoverflow.com/questions/9506871/image-compression-by-size-iphone-sdk 希望能帮到你。 |
|
hohohoSep 6, 2015 via iPhone
5
先等比例缩放图片 size ,然后再用四楼的方法循环压缩。
|
|
pubbySep 6, 2015
6
|
|
xi_linSep 6, 2015
7
在小内存机型上压大图片直接用 UIImageJPEGRepresentation 有可能会死得很惨。。
推荐 https://gist.github.com/jder/4331450#file-downscaling-alassets |
|
8
@fghfjujiber 正在用这个方法。有问题:
1.这个方法不一定能压到指定以下 2. UIImageJPEGRepresentation 有时会越压越大 3. 我先等比缩放图片, UIImageJPEGRepresentation 有时会还原图片分辨率大小 @hohoho |
|
kobe1941Sep 7, 2015
9
@fghfjujiber 我之前也这么干过,然后有些长图清晰度不好,就把需求改了,以压缩比率优先,图片大小不管啦! JPEG 的压缩算法真的很不错的
|