在使用此代码从照片库中选择图片后,我会绑定以检查我的图像大小。
NSData *imageData1 = [[NSData alloc] initWithData:UIImageJPEGRepresentation((imageview.image), 0.5)];
int imageSize = imageData1.length;
NSLog(@"SIZE OF IMAGE: %i ", imageSize);
但展示的是这样的东西。
SIZE OF IMAGE: 237125
但我想查看的图像大小以MB格式,如25 MB,如何做,请告诉我如何做。
谢谢。
发布于 2014-02-26 02:00:21
imageSize
的数据长度以字节为单位。你需要把它转换成Mb
NSLog(@"SIZE OF IMAGE: %i Mb", imageSize/1024/1024);
更新:
您还可以使用以下代码
NSLog(@"SIZE OF IMAGE: %.2f Mb", (float)imageSize/1024/1024);
接收输出,如
图像大小:0.23Mb
尺寸小于1MB。
发布于 2014-02-26 02:03:32
[NSByteCountFormatter stringFromByteCount:imageSize
countStyle:NSByteCountFormatterCountStyleFile];
发布于 2017-04-07 08:41:14
补充@rounak的答案,在Swift 3中
ByteCountFormatter.string(fromByteCount: Int64(imageSize), countStyle: .file)
https://stackoverflow.com/questions/22037808
复制