图像融为一体pression由大小 - iPhone SDK [英] image compression by size - iPhone SDK

查看:100
本文介绍了图像融为一体pression由大小 - iPhone SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想COM preSS图像(相机/照片库),然后将其发送到服务器。我知道我可以融为一体preSS通过高度和宽度,但我想COM preSS按大小为固定大小(200 KB)图像仅保持原有的高度和宽度。在JPEGRe presentation比例系数不重present大小只有玉米pression质量。我怎样才能做到这一点(COM preSS到一个固定大小),而无需使用任何第三方库?
感谢您的帮助。

I would like to compress images (camera/photo library) and then send it to the server. I know I can compress by height and width, but I would like to compress the images by size to a fixed size (200 KB) only and keep the original height and width. The scale factor in JPEGRepresentation does not represent the size and only compression quality. How can I achieve this (compress to a fixed size) without using any third party library? Thanks for any help.

推荐答案

下面有一些例子code,它会试图COM preSS为你的图像,使其不超过或者是最大的COM pression或最大文件大小

Heres some example code that will attempt to compress an image for you so that it doesn't exceed either a max compression or maximum file size

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);
}

这篇关于图像融为一体pression由大小 - iPhone SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆