2009-06-20 127 views
2

我正在處理的應用程序處理用戶的圖像,並在用戶完成後,他們可以保存該照片。我沒有問題捕獲屏幕並保存它(因爲我想要保存圖像中的一些標籤),但此調用:iPhone:將圖像保存到特定相冊

UIImageWriteToSavedPhotosAlbum([self getScreenAsImage],nil,nil,nil);

只能讓我保存到「已保存的照片」相冊。理想情況下,我想創建一個以我正在工作的應用程序命名的專輯,並將其保存在那裏,以便它們全部存儲在一起(例如像模擬器上的夏威夷或畢業日專輯)。如果在特定相冊中啓動圖像選擇器,那也不錯。有人知道怎麼做嗎?最重要的部分是能夠將其保存在相冊中,能夠在該相冊中啓動選取器是次要的。

回答

-1

據我所知,蘋果公司沒有公開SDK來允許這樣做。在審查UIKit函數參考後,我的恐懼似乎得到證實。

+0

感謝布拉德,這基本上是我在廣泛的谷歌搜索後盤算,所以這是好事,有確認。 – Codezy 2009-06-20 20:01:20

0

可以使用ALAssetsLibrary這樣做的:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 

[library saveImage:image toAlbum:@"Midhun" withCompletionBlock:^(NSError *error) { 
     if (error!=nil) { 
      NSLog(@"Error: %@", [error description]); 
     } 
    }]; 

檢查也是本教程:Custom Photo Album

2

有一種方法可以做到這一點,蘋果只是沒有讓它變得更簡單。

有一個自定義類別,將功能添加到ALAssetsLibrary。

的Git回購該類別可以發現here

,如果你正在使用的CocoaPods你可以用

pod 'ALAssetsLibrary-CustomPhotoAlbum' 

您需要實例化一個ALAssetsLibrary對象,並調用下面的方法得到它

- (void)saveImage:(UIImage *)image 
     toAlbum:(NSString *)albumName 
    completion:(ALAssetsLibraryWriteImageCompletionBlock)completion 
     failure:(ALAssetsLibraryAccessFailureBlock)failure 

類似下面

導入:

#import "ALAssetsLibrary+CustomPhotoAlbum.h" //Source Included (Git) 

#import <ALAssetsLibrary+CustomPhotoAlbum.h> //Cocoapods 

電話:

ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init]; 
[assetsLib saveImage:imageToSave 
         toAlbum:@"AlbumName" 
        completion:completionBlock 
         failure:failureBlock]; 
相關問題