当我在将图像放入 UIImage 后对图像的大小进行 NSLog 时,它会以预期的大小出现。但是,当我使用 CGImageSource 尝试此操作时,我得到的图像大小是预期的两倍。这是我为此使用的代码:
NSString *fullPath = [self fullPathForThumbnail];
NSURL *imageFileURL = [NSURL fileURLWithPath:fullPath];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)imageFileURL, NULL);
if (imageSource == NULL) {
// Error loading image
return NO;
}
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache,
nil];
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (__bridge CFDictionaryRef)options);
CGSize originalSize;
if (imageProperties) {
NSNumber *width = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
NSNumber *height = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
originalSize = CGSizeMake(width.floatValue, height.floatValue);
CFRelease(imageProperties);
}
这只发生在视网膜图像上;非视网膜图像似乎是正确的尺寸。