将图片保存在iPhone的相册中
2011-06-03 15:47
411 查看
有时候你的应用需要将应用中的图片保存到用户iPhone或者iTouch的相册中。 可以使用UIKit的这个类方法来完成。
image
要保存到用户设备中的图片
completionTarget
当保存完成后,回调方法所在的对象
completionSelector
当保存完成后,所调用的回调方法。 形式如下:
- (
void
)
image: (
UIImage *)
image
didFinishSavingWithError: (
NSError
*)
error
contextInfo: (
void
*)
contextInfo;
contextInfo
可选的参数,保存了一个指向context数据的指针,它将传递给回调方法。
比如你可以这样来写一个存贮照片的方法:
// 要保存的图片
UIImage *img = [
UIImage imageNamed:@"ImageName.png"
]
;
// 保存图片到相册中
UIImageWriteToSavedPhotosAlbum(
img, self, @selector
(
image:didFinishSavingWithError:contextInfo:)
, nil
)
;
回调方法看起来可能是这样:
保存当前视图:
#import
<QuartzCore/QuartzCore.h>
UIGraphicsBeginImageContext(currentView.bounds
.size
); //currentView
当前的
view
[currentView.
layer
renderInContext:
UIGraphicsGetCurrentContext()];
UIImage *viewImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil
, nil
, nil
);
void UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo );
image
要保存到用户设备中的图片
completionTarget
当保存完成后,回调方法所在的对象
completionSelector
当保存完成后,所调用的回调方法。 形式如下:
- (
void
)
image: (
UIImage *)
image
didFinishSavingWithError: (
NSError
*)
error
contextInfo: (
void
*)
contextInfo;
contextInfo
可选的参数,保存了一个指向context数据的指针,它将传递给回调方法。
比如你可以这样来写一个存贮照片的方法:
// 要保存的图片
UIImage *img = [
UIImage imageNamed:@"ImageName.png"
]
;
// 保存图片到相册中
UIImageWriteToSavedPhotosAlbum(
img, self, @selector
(
image:didFinishSavingWithError:contextInfo:)
, nil
)
;
回调方法看起来可能是这样:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { // Was there an error? if (error != NULL) { // Show error message… } else // No errors { // Show message image successfully saved } }
保存当前视图:
#import
<QuartzCore/QuartzCore.h>
UIGraphicsBeginImageContext(currentView.bounds
.size
); //currentView
当前的
view
[currentView.
layer
renderInContext:
UIGraphicsGetCurrentContext()];
UIImage *viewImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil
, nil
, nil
);
相关文章推荐
- unity3d 保存(截图、拍照)图片 到Android IPhone手机相册
- 将图片保存在iPhone的相册中
- iPhone应用程序 将图片保存到相册实例
- 保存图片到相册 iphone UIImageWriteToSavedPhotosAlbum 保存图片
- 将图片保存在iPhone的相册中
- iOS 将图片保存到iPhone本地相册
- iPhone应用程序 将图片保存到相册实例
- 将图片保存在iPhone的相册中
- iphone开发——保存图片到相册及容错处理
- iPhone应用程序 将图片保存到相册实例
- 将图片保存在iPhone的相册中
- Android把svg图片转为jpg保存到相册图库
- android保存图片到本地并可以在相册中显示出来
- 在手机相册中保存图片失败
- [置顶] cordova开发 升级xcode9 打包保存图片访问相册闪退
- Android将图片保存至相册刷新问题记录
- iOS _ 图片保存到本地相册
- Android 保存图片到手机相册
- Android相机、相册获取图片显示并保存到SD卡
- android如何将生成的图片保存至手机相册并显示出来