2011-05-18 126 views
2

嘿傢伙,我目前正試圖從用戶通過UIIMagePickerController選擇的圖像中獲取EXIF數據。我似乎無法理解我將如何獲得我可以用於CGImageSourceCreateWithURL((CFURLRef)someURL,nil)的路徑。獲取CGImageSourceRef的圖像路徑

當我嘗試使用UIImagePickerControllerReferenceURL控制檯吐出一個相當不錯的錯誤:<ERROR> CGImageSourceCreateWithURLCFURLCreateDataAndPropertiesFromResource failed with error code -11.。我很難過,我開始認爲我來自一個錯誤的角度,因爲CGImageSourceRef類型通常用於創建一個圖像,而我已經有一個UIImage。任何人都可以在這個問題上了解一些情況,請隨時這樣做。

- (void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info {

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; 
[self dismissModalViewControllerAnimated:YES]; 
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){ 
    image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    NSLog(@"%@",[info objectForKey:UIImagePickerControllerReferenceURL]); 
    //Outputs: assets-library://asset/asset.JPG?id=1000000006&ext=JPG 
    CGImageSourceCreateWithURL((CFURLRef)[info objectForKey:UIImagePickerControllerReferenceURL], nil); 

    //The plan is to somehow get a CGImageSourceRef object from the 
    //UIImage provided by the [info UIImagePickerControllerOriginalImage], i just don't know how to get this object, 
    // for it requires the URL to the image, wich i don't seem to have. 
    } 

} 

CNC中 將使用更多的緊張所提供的解決方法。謝謝閱讀。

+0

你能發表一些代碼嗎? – 2011-05-18 15:45:41

+0

如果這對你有幫助,你應該+1顛簸@more_tension。 – 2011-05-18 17:10:47

+0

我碰到了實際的答案,它進一步下降:) – Uxxish 2011-05-18 17:12:46

回答

5

錯誤代碼-11意味着URL方案無法識別,也就是說CFURL不知道如何處理以assets-library開頭的URL://。

爲什麼你認爲在這種情況下你需要一個CGImageSourceRef?

+0

因爲我打算使用ImageIO框架從圖像中讀取EXIF數據。此方法('CGImageSourceCopyPropertiesAtIndex')需要傳遞一個CGImageSourceRef對象作爲參數。我想我還需要使用'CGImageSourceRef',它實際上是對'UIImagePickerController'返回的圖像的引用。我只是不知道如何去檢索正確的URL。我認爲資產URL並不是我正在尋找的,因爲我嘗試了'ALAsset'框架,結果不夠。 – Uxxish 2011-05-18 16:15:04

+1

解決方法可能是在本地保存原始圖像數據,然後使用'CGImageSourceCreateWithURL'來獲取'CGImageSource'。 – 2011-05-18 16:33:54

+0

嗯,這可能是一種可能性,我將不得不確保所有的EXIF數據都保留在這個過程中,但是謝謝你! – Uxxish 2011-05-18 16:45:40

-1

嘗試使用

ALAssetRepresentation *表示= [yourAsset defaultRepresentation];
NSDictionary * metadataDict = [[representation metadata] retain];

+0

[表示元數據]不會返回像Camera或光圈等所有EXIF信息。 – Jordan 2013-10-07 18:00:33