2012-04-06 16 views

答えて

0

私は答えここに発見した:http://oleb.net/blog/2011/09/accessing-image-properties-without-loading-the-image-into-memory/

#import <ImageIO/ImageIO.h> 

NSURL *imageFileURL = [NSURL fileURLWithPath:...]; 
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL); 
if (imageSource == NULL) { 
    // Error loading image 
    ... 
    return; 
} 

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: 
         [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache, 
         nil]; 
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options); 
if (imageProperties) { 
    NSNumber *width = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth); 
    NSNumber *height = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight); 
    NSLog(@"Image dimensions: %@ x %@ px", width, height); 
    CFRelease(imageProperties); 
} 

は、我々は、画像をロードせずに、ファイルから任意のメタデータにアクセスすることができます。

関連する問題