2012-07-17 87 views
1

我在努力弄清楚如何從UIImagePickerControllerReferenceURL獲取圖像(我知道我可以直接從UIImagePickerControllerOriginalImage獲得它,但是我有理由不想)。下面是我有如何從UIImagePickerControllerReferenceURL獲取UIImage

/* 
* Responds when an image is selected (from browsing) 
*/ 
-(void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
     UIImage *image = [self obtainImageAtURLPath:[info objectForKey:UIImagePickerControllerReferenceURL]]; 
     if(!image) return; 
     //...more code here 
} 
- (UIImage *) obtainImageAtURLPath:(NSURL *) urlPath 
{ 
    UIImage *image = [UIImage imageWithContentsOfFile:[urlPath path]]; 
    return image; 
} 

然而,當我這樣做,我總是得到nil,而不是我的形象。 urlPath存在;但是,它不想被轉換爲UIImage。請幫助。

如果我打印出來NSLog(@"%@", urlPath)我得到assets-library://asset/asset.JPG?id=53784678-BD17-4EE4-9A96-601B81012AFE&ext=JPG

如果我打印出來NSLog(@"%@", [urlPath path])我得到/asset.JPG

+0

它是什麼樣的圖像?顯示網址 – Dustin 2012-07-17 13:34:03

+0

這是使用iPad相機拍攝的圖像。我會在一秒內發佈實際路徑 – Nosrettap 2012-07-17 13:35:00

+0

@Dustin在上面的編輯中查看實際路徑。謝謝 – Nosrettap 2012-07-17 13:37:07

回答