2011-04-13 60 views
0

我剛開始開發一個應用程序,我想要自動同步存儲在用戶的照片庫中的所有圖像作爲資產。iPhone自動同步照片與我們的應用程序使用AlAssetLibrary

我能夠獲取那些存儲爲資產的圖像的URL。

e.g. assets-library://asset/asset.JPG?id=1000000003&ext=JPG 

現在,我該如何在複製此圖片我的應用程序文件的目錄或者我怎麼只顯示圖像的獲取,在NSDataUIImage存儲在資產?

在此先感謝。

回答

1

你可以只要你得到了資產使用下面的代碼在UIImagePickerControllerDelegate委託執行

- (void) imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info { 

    //obtaining saving path 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"my_photo.png"]; 

    //extracting image from the picker and saving it 
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage]; 
    NSData *imageData = UIImagePNGRepresentation(editedImage); 
    [imageData writeToFile:imagePath atomically:YES]; 

} 
+1

@RuchirAgile,複製它馬上爲@Jhaliya建議。 – 2011-04-13 12:15:56

+0

我沒有使用ImagePickerController作爲使用ImagePicker,你一次只能得到一個圖像。我想要在啓動應用程序時同步/獲取所有照片。 – 2011-04-13 12:44:44

相關問題