How to test the size of a UIImage (in bytes)

We can use NSData’s length method for this. Imagine your UIImage is yourImage:

NSData *imageData = UIImageJPEGRepresentation(yourImage, 1);
NSLog(@"Size of your image is %d bytes", [imageData length])

[imageData length] returns a double in bytes, which will be the size of your image.

This is useful if you’d like to save something and you’re limited in size, such as iCloud Key Value storage where a data object may only be 1MB in size or smaller.





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.