My application lets user take a picture with default camera on iPhone and send it to a server. Before sending it I would like to check the image size and let's say if the size is larger than 500 KB I would let the user know filesize is too big and would not send it. Is there a way to check the image size programmatically? Help would be appreciated.
If you convert it to NSData
, you can check the length
property. The file size in MB is bytes divide by 2^20.
To convert to NSData use UIImagePNGRepresentation()
UIImage *myImage = ...
NSData *imageData = UIImagePNGRepresentation(myImage);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.