Какао: Получение метаданных файла изображения
Я создаю приложение, которое позволяет пользователям выбирать файл и / или папку либо локально, либо по сети и после некоторой фильтрации перечислять содержимое этого выбора в NSTableView (без скрытых файлов, только принимая.tif, .eps). Затем пользователь может выбрать имя файла из списка и затем показать ему метаданные файлов. По крайней мере, это то, чего я хочу. Прямо сейчас я получаю нулевое значение для метаданных. Вот мой код:
- (void)tableViewSelectionDidChange:(NSNotification *)notif {
NSDictionary* metadata = [[NSDictionary alloc] init];
//get selected item
NSString* rowData = [fileList objectAtIndex:[tblFileList selectedRow]];
//set path to file selected
NSString* filePath = [NSString stringWithFormat:@"%@/%@", objPath, rowData];
//declare a file manager
NSFileManager* fileManager = [[NSFileManager alloc] init];
//check to see if the file exists
if ([fileManager fileExistsAtPath:filePath] == YES) {
//escape all the garbage in the string
NSString *percentEscapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)filePath, NULL, NULL, kCFStringEncodingUTF8);
//convert path to NSURL
NSURL* filePathURL = [[NSURL alloc] initFileURLWithPath:percentEscapedString];
NSError* error;
NSLog(@"%@", [filePathURL checkResourceIsReachableAndReturnError:error]);
//declare a cg source reference
CGImageSourceRef sourceRef;
//set the cg source references to the image by passign its url path
sourceRef = CGImageSourceCreateWithURL((CFURLRef)filePathURL, NULL);
//set a dictionary with the image metadata from the source reference
metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
NSLog(@"%@", metadata);
[filePathURL release];
} else {
[self showAlert:@"I cannot find this file."];
}
[fileManager release];
}
Я предполагаю, что проблема здесь - это CFURLREF в CGImageSourceCreateWithURL. Вместо NSURL я должен использовать что-то еще?
Спасибо
Вот путь, который я передаю (зарегистрирован из filePathURL): file://localhost/Volumes/STORAGE%20SVR/Illustration-Wofford/Illustration%20Pickup/Archive/AL013111_IL_Communication.eps
1 ответ
Я не могу сказать, откуда взялась часть "localhost" в URL вашего файла, но я думаю, что это виновник. URL файла обычно не содержит части "localhost". В вашем примере это должно выглядеть так:
file:///Volumes/STORAGE%20SVR/Illustration-Wofford/Illustration%20Pickup/Archive/AL013111_IL_Communication.eps
Но я уверен, что вы уже поняли это:)
Обновление: я исправлен комментарием Майка: file://localhost/...
это то же самое, что file:///...
!