2009-06-20 312 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];