How to get Size of UIImage in Bytes in iOS 4.0+?

后端 未结 4 1165
北恋
北恋 2021-02-08 08:01

I am trying to pick an image from the photo library or from the camera.
The delegate method:

- (void)imagePickerController:(UIImagePickerController *)picker d         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-02-08 08:28

    From:@fbrereto's answer:

    The underlying data of a UIImage can vary, so for the same "image" one can have varying sizes of data. One thing you can do is use UIImagePNGRepresentation or UIImageJPEGRepresentation to get the equivalent NSData constructs for either, then check the size of that.

    From:@Meet's answer:

     UIImage *img = [UIImage imageNamed:@"sample.png"];
     NSData *imgData = UIImageJPEGRepresentation(img, 1.0); 
     NSLog(@"Size of Image(bytes):%d",[imgData length]);
    

提交回复
热议问题