С прошивкой 4.0 IOS SDK включает CGImageSource...
functions (в рамках ImageIO). Это очень гибкий API для запроса метаданных без загрузки изображения в память. Получение размеров пикселов изображения должны работать, как это (не забудьте включить ImageIO.framework в вашей цели):
#import <ImageIO/ImageIO.h>
NSURL *imageFileURL = [NSURL fileURLWithPath:...];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
if (imageSource == NULL) {
// Error loading image
...
return;
}
CGFloat width = 0.0f, height = 0.0f;
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
CFRelease(imageSource);
if (imageProperties != NULL) {
CFNumberRef widthNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
if (widthNum != NULL) {
CFNumberGetValue(widthNum, kCFNumberCGFloatType, &width);
}
CFNumberRef heightNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
if (heightNum != NULL) {
CFNumberGetValue(heightNum, kCFNumberCGFloatType, &height);
}
// Check orientation and flip size if required
CFNumberRef orientationNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyOrientation);
if (orientationNum != NULL) {
int orientation;
CFNumberGetValue(orientationNum, kCFNumberIntType, &orientation);
if (orientation > 4) {
CGFloat temp = width;
width = height;
height = temp;
}
}
CFRelease(imageProperties);
}
NSLog(@"Image dimensions: %.0f x %.0f px", width, height);
(адаптировано из «Программирование с кварцем» по Gelphman и Ладеном, листинг 9.5, страница 228)
Это хороший вопрос. Android предоставляет средства для этого, но я не знаю решения iOS. EDIT: Это было задано раньше. http://stackoverflow.com/questions/1551300/get-size-of-image-without-loading-in-to-memory – Justin
Я искал раньше, но я не мог найти его! большое спасибо! – koda