2013-07-18 89 views
0

我的问题真的很烦人。我正在创建拍摄照片并需要将其保存到自定义图库的应用程序。我发现了几个教程,如何用AlAssetsLibrary来做到这一点,但有一个很大的问题......没有saveImage:toAlbum:withCompletionBlock:方法。我使用addAssetsGroupAlbumWithName:resultBlock:failureBlock:来创建自定义相册,但是我无法将图像保存到此图库中!我正在使用iOS 6 iPhone 4.保存照片到自定义库

任何想法!?

+1

您是否检查过[this](http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/)? – TheTiger

+0

是啊,我刚才看到了这个,但看看@Vignesh回答下的评论:) – cojoj

回答

1

您在问题saveImage:toAlbum:withCompletionBlock中提到的方法不是ALAssetsLibrary的一部分。这种方法写在ALAssetLibary's category。你必须在你的班级中输入该类别才能使用该方法。

要了解关于客观C类别的更多信息,请查看开发人员reference

+0

谢谢!我没有意识到这是一个类别...我正在通过网络搜索,并撕毁我的头发,最后:D – cojoj

+0

我还有一个问题。是否可以修改此类别不将此照片保存到相机胶卷?只有自定义相册。 – cojoj

+0

@Cojoj。不用谢。这是不可能的。所有的图像将被存储在相机胶卷中。你不能阻止这一点。 – Vignesh

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 [email protected]"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]; 
} 

这将解决你的情况。