How to get the Size (KB) of UIImage

后端 未结 2 1109
野趣味
野趣味 2021-02-07 12:05

I am getting Image from didFinishPickingMediaWithInfo.

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


        
相关标签:
2条回答
  • 2021-02-07 12:17

    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));
    
    0 讨论(0)
  • 2021-02-07 12:22
        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;
    
    0 讨论(0)
提交回复
热议问题