2014-03-05 64 views
0

這是我需要的。從沒有選擇器的照片庫加載圖像?

我需要我的用戶能夠從照片庫中選擇圖片,但是,他們不需要每次使用時都必須重新播放它。相反,我想記住照片的路徑,以便將來能夠加載它。這可能嗎?如果不是,有什麼選擇?是否有可能將照片緩存到本地文件夾或地方?

感謝

回答

1

你不能把所拍攝圖像的參考,所以你需要,你建議你的自我,保存圖像的本地副本。您可以使用UIImagePicker讓用戶選擇圖像,然後將其保存在本地:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    UIImage* image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage]; 
    NSData *imageData = UIImagePNGRepresentation(image); 

//save the imageData to document dir. You could also save it to the cache... 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documents = [paths objectAtIndex:0]; 
    NSString *finalPath = [documents stringByAppendingPathComponent:@"myImageName.png"]; 
    [imageData writeToFile:finalPath atomically:YES]; 
} 
+0

這太棒了!謝謝! – jmasterx

相關問題