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

- by

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.

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site witout any pesky ads! More details here.

Add your voice!

This site uses Akismet to reduce spam. Learn how your comment data is processed.