Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get size of a UIImage (bytes length) not height and width

Tags:

iphone

uiimage

I'm trying to get the length of a UIImage. Not the width or height of the image, but the size of the data.

like image 508
Kevin Avatar asked Aug 18 '09 21:08

Kevin


2 Answers

 UIImage *img = [UIImage imageNamed:@"sample.png"];  NSData *imgData = UIImageJPEGRepresentation(img, 1.0);   NSLog(@"Size of Image(bytes):%d",[imgData length]); 
like image 128
Meet Avatar answered Sep 21 '22 19:09

Meet


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.

like image 25
fbrereto Avatar answered Sep 18 '22 19:09

fbrereto