我需要通过蓝牙发送图片后显示在硬件上,硬件工程师有一个要求,我需要传输的图片数据不超过2888字节,但是当我在压缩图片时压缩到超过5000字节的时间无法被压缩,我该怎么办?
发布于 2018-01-02 16:30:57
我认为您需要根据图像大小限制多次压缩图像。你可以按照下面的方法进行图像压缩,
CGFloat compression = 0.9f;
CGFloat maxCompression = 0.1f;
int maxFileSize = 2888;
NSData *imageData = UIImageJPEGRepresentation(yourImage, compression);
while ([imageData length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1;
imageData = UIImageJPEGRepresentation(yourImage, compression);
}
https://stackoverflow.com/questions/48057411
复制相似问题