0
PNGファイルから幅と高さのみを取得する必要があります。 UIImage
とすることはできますか?その理由は、まれに、奇数幅とRGB8形式の一部の画像で、UIImageがlibpng
とは異なる寸法を返すためです)。UIImage initWithContentsOfFile:... - 寸法のみを取得する必要があります
PNGファイルから幅と高さのみを取得する必要があります。 UIImage
とすることはできますか?その理由は、まれに、奇数幅とRGB8形式の一部の画像で、UIImageがlibpng
とは異なる寸法を返すためです)。UIImage initWithContentsOfFile:... - 寸法のみを取得する必要があります
私は答えここに発見した: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);
}
は、我々は、画像をロードせずに、ファイルから任意のメタデータにアクセスすることができます。