本文介绍了如何获取从`UIImagePickerController`收到的图像的压缩文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过camara或库知道 UIImagePickerController 拍摄的图像大小。有没有办法找到它?

I want to know the size of image taken by UIImagePickerController by camara or library. Is there any way to find that ?

要求就像,

如果图像大小超过1 MB比我想要压缩它。

If image size is more than 1 MB than i want to compress it.

提前感谢。

推荐答案

试试这个:

try this:

CGFloat compression = 0.8f;
CGFloat maxCompression = 0.1f;
int maxFileSize = 1024;
UIImage *img =[UIImage imageNamed:@"anyimg.jpg"];
NSData *imageData = UIImageJPEGRepresentation(img, compression);

while ([imageData length] > maxFileSize && compression > maxCompression)
{
    compression -= 0.1;
    imageData = UIImageJPEGRepresentation(img, compression);
    NSLog(@"%d",[imageData length]);
}
NSLog(@"image size %d",[imageData length]);

获取图像尺寸:

NSData * data_size = UIImagePNGRepresentation(yourImage);

int image_size = [data_size length];

这篇关于如何获取从`UIImagePickerController`收到的图像的压缩文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 03:23