答案 0 :(得分:1)
使用UIImage
从捆绑包中的图片中创建imageNamed:
对象,然后使用UIImageWriteToSavedPhotosAlbum()
将其保存到照片库。
UIImage *image = [UIImage imageNamed:@"wallpaper.jpg"];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
有关UIImageWriteToSavedPhotosAlbum()
(回调函数等)选项的更多信息,您可以查看UIKit Function Reference
。
答案 1 :(得分:1)
调用UIImageWriteToSavedPhotosAlbum,我相信看起来像这样:
UIImageWriteToSavedPhotosAlbum(
UIImage* image,
id completionTarget,
SEL completionSelector,
void* contextInfo
);
使用它的一种方法是:
UIImage* myImage = [UIImage imageNamed:@"image.png"];
UIImageWriteToSavedPhotosAlbum(myImage, self, @selector(image:didFinishSavingWithError:contextInfo), nil);
如果您希望在成功或失败时收到通知,则只需设置完成目标和完成选择器。如果是这样,请不要忘记将此方法添加到课程中:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void*)contextInfo
{
if (error)
{
// Do something on error... (like show a UIAlert for example)
}
else
{
// Do something on success... (maybe show a "Your image was saved" alert
}
}
图像不会立即保存,并且可能会在过程中出错,因此这可能很有用。
你也可以使用ALAssetsLibrary,我相信它会是这样的:
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[myImage CGImage] orientation:(ALAssetOrientation)[myImage imageOrientation] completionBlock:^(NSURL* assetURL, NSError* error)
{
if (error)
{
// Do something on error... (like show a UIAlert for example)
}
else
{
// Do something on success... (maybe show a "Your image was saved" alert
}
}];
希望这会有所帮助。