【问题标题】:How to save photo in a particular album in iOS如何在 iOS 中将照片保存在特定相册中
【发布时间】:2013-01-16 04:43:00
【问题描述】:

我正在使用此代码将图像保存到相册中,但图像正在保存在相机胶卷相册中。我想将图像保存在 WEAVE 相册中。我正在使用此代码:

CGRect screenRect=CGRectMake(0, 0, viewPlay.frame.size.width, viewPlay.frame.size.height);
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx=UIGraphicsGetCurrentContext();
[[UIColor whiteColor] set];
CGContextFillRect(ctx, screenRect);
[self->viewPlay.layer renderInContext:ctx];
UIImage *screenImage=UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();

这段代码对我来说很好用。请给我任何建议,我在这里做了哪些更改以将图像保存到 WEAVE 文件夹中。

【问题讨论】:

    标签: ios


    【解决方案1】:

    您可以使用以下代码来执行此操作:

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

    也请查看本教程:Custom Photo Album

    更多关于ALAssetsLibrary的信息

    【讨论】:

    • 感谢您的回答。我试过了,但是这个代码只保存了一次图片。我想在该相册中保存多张图片。如何修复这个错误?请帮帮我。
    • @SanjayJoshi:意思是当你在该函数上传递另一个图像时发生了什么?
    • 它不会将另一张图片保存到同一个文件夹中。
    • 你能再帮我一次吗?我想在保存时更改图像的名称。怎么办?
    • @SanjayJoshi:你的意思是用一个名字把文件保存在照片库中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多