How to save picture to iPhone photo library?
我需要做什么才能将我的程序生成的图像(可能来自相机,可能不是)保存到iPhone上的系统照片库中?
You can use this function:
UIImageWriteToSavedPhotosAlbum(UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo);
You only need completionTarget , completionSelector and contextInfo if you want to be notified when the UIImage
is done saving, otherwise you can pass in nil
.
See the official documentation for UIImageWriteToSavedPhotosAlbum()
.
Deprecated in iOS 9.0.
There`s much more fast then UIImageWriteToSavedPhotosAlbum way to do it using iOS 4.0+ AssetsLibrary framework
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
// TODO: error handling
} else {
// TODO: success handling
}
}];
[library release];
The simplest way is:
UIImageWriteToSavedPhotosAlbum(myUIImage, nil, nil, nil);
For Swift
, you can refer to Saving to the iOS photo library using swift
上一篇: 如何附加多个控制器来查看其子视图
下一篇: 如何将图片保存到iPhone照片库?