如何获取UIImage的大小(KB)

时间:2013-02-19 12:03:12

标签: ios objective-c xcode uiimage

我从didFinishPickingMediaWithInfo获得了图片。

UIImage *originalImage = (UIImage*)[info valueForKey:UIImagePickerControllerOriginalImage];

我想在Kb中获得Image的大小。

2 个答案:

答案 0 :(得分:24)

    UIImage *originalImage = (UIImage*)[info valueForKey:UIImagePickerControllerOriginalImage];
    NSData *imgData = UIImageJPEGRepresentation(originalImage, 1); //1 it represents the quality of the image.
    NSLog(@"Size of Image(bytes):%d",[imgData length]);
    imgData = nil;

答案 1 :(得分:0)

我认为操作size (kb)originalImage的内存大小,对吗?

查看ARC下malloc_size的使用情况,请参阅this

#import <malloc/malloc.h>

NSLog(@"Size of %@: %zd", NSStringFromClass([originalImage class]), malloc_size((__bridge const void *)originalImage));