Getting Image Size in kb Programmatically in Xcode

NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

path = [[pathArr objectAtIndex:0]stringByAppendingPathComponent:[NSString stringWithFormat:@"imagename.png"]];  // Getting the path of the image, whose size is to be calculated.

NSFileManager *fileManager = [NSFileManager defaultManager]; // Creating the object of file manager.

NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:path traverseLink:YES]; // Getting the attributes of the file in the path.

if(fileAttributes != nil)


NSString *fileSize = [fileAttributes objectForKey:@"NSFileSize"]; // Getting the value corresponding to the key NSFileSize from the attributes array and storing it to a string..

NSLog(@"File size: %@ kb", fileSize);


Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>