15

I am getting Image from didFinishPickingMediaWithInfo.

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

I want to get the size of Image in Kb.

Venk
  • 5,949
  • 9
  • 41
  • 52
Amir iDev
  • 1,257
  • 2
  • 15
  • 29

2 Answers2

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;
Mutawe
  • 6,464
  • 3
  • 47
  • 90
  • 11
    Looks expensive! You are creating a duplicate on-disk representation just to get its size! – trojanfoe Feb 19 '13 at 13:09
  • 1
    @trojanfoe any other solution? – Amir iDev Feb 19 '13 at 15:18
  • 1
    @AmiriDev if it came from disk then you can get the url from the dictionary passed with that delegate call and then use `NSFileManager` to get file information. I am only guessing though... – trojanfoe Feb 19 '13 at 15:20
0

I think the op's size (kb) is the memory size of originalImage, right?

Check out the usage about malloc_size under the ARC refer to this.

#import <malloc/malloc.h>

NSLog(@"Size of %@: %zd", NSStringFromClass([originalImage class]), malloc_size((__bridge const void *)originalImage));
Itachi
  • 5,777
  • 2
  • 37
  • 69