Sometimes you want to retrieve an image file's properties but don't need to display (and hence read) the image itself. This is particularly important if you need to retrieve the properties of many image files, as reading the whole file into memory takes time and resources. You can access the image properties using the Image I/O framework:
#import <ImageIO/ImageIO.h>
//...
//Some path
NSString* path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"back-btn.png"];
NSURL* imageFileURL = [NSURL fileURLWithPath:path];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)imageFileURL, NULL);
if (imageSource) {
NSDictionary* options = @{(NSString*)kCGImageSourceShouldCache:@NO};
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (__bridge CFDictionaryRef)options);
if (imageProperties) {
NSLog( @"properties: %@", imageProperties);
CFRelease(imageProperties);
}
} else {
NSLog(@" Error loading image");
}
Courtesy of Accessing Image Properties Without Loading the Image into Memory (slightly modified, modernized)
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.