我的问题真烦人。我正在创建应用程序,它需要将照片保存到自定义库中。我已经找到了几个教程如何使用AlAssetsLibrary做这个,但有一个大问题......没有saveImage:toAlbum:withCompletionBlock:
方法。我使用addAssetsGroupAlbumWithName:resultBlock:failureBlock:
来创建自定义相册,但我无法将图像保存到此库中!我正在使用iOS 6 iPhone 4.
任何想法!?
答案 0 :(得分:1)
问题saveImage:toAlbum:withCompletionBlock
中提到的方法不属于ALAssetsLibrary。此方法用ALAssetLibary's category编写。您必须在类中导入类别才能使用该方法。
要了解有关目标C类别的更多信息,请查看开发人员reference。
答案 1 :(得分:0)
看这里:
http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/
这里有一个Stackoverflow线程:Save Photos to Custom Album in iPhones Photo Library
答案 2 :(得分:0)
如果您使用的是AssetsLibrary,则可以编写此代码
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagePicker;
if (buttonIndex < 2)
{
self.library = [[[ALAssetsLibrary alloc] init] autorelease];
self.imageEditor = [[[DemoImageEditor alloc] initWithNibName:@"DemoImageEditor" bundle:nil] autorelease];
self.imageEditor.doneCallback = ^(UIImage *editedImage, BOOL canceled){
if(!canceled)
{
anotherImage = true;
NSString *imageName;
imageName =@"Abc.jpg";
UIImageWriteToSavedPhotosAlbum(editedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
editedImage = [self scaleImage:editedImage toSize:CGSizeMake(600,600)];
[[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(editedImage)forKey:@"image"];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
else
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert release];
}
它将解决您的情况。