iPhone应用程序 将图片保存到相册实例
2013-07-09 13:00
495 查看
iPhone应用程序 将图片保存到相册实例是本文要介绍的内容,主要是以代码来实现本文要表现的内容,进入话题。有时候你的应用需要将应用中的图片保存到用户iPhone或者iTouch的相册中。
可以使用UIKit的这个类方法来完成。
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 );
小结:iPhone应用程序 将图片保存到相册实例的内容介绍完了,希望本文对你有所帮助!
可以使用UIKit的这个类方法来完成。
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 );
小结:iPhone应用程序 将图片保存到相册实例的内容介绍完了,希望本文对你有所帮助!
相关文章推荐
- iPhone应用程序 将图片保存到相册实例
- iPhone应用程序 将图片保存到相册实例
- unity3d 保存(截图、拍照)图片 到Android IPhone手机相册
- 将图片保存在iPhone的相册中
- 与众不同 windows phone (16) - Media(媒体)之编辑图片, 保存图片到相册, 与图片的上下文菜单“应用程序...”和“共享...”关联, 与 Windows Phone 的图片中心集成
- 保存图片到相册 iphone UIImageWriteToSavedPhotosAlbum 保存图片
- iPhone模拟器之将图片添加到相册实例
- iOS 把图片保存到相册,并获取图片文件名的实例
- IOS 如何保存图片到相册实例
- 将图片保存在iPhone的相册中
- iOS 将图片保存到iPhone本地相册
- 将图片保存在iPhone的相册中
- 与众不同 windows phone (16) - Media(媒体)之编辑图片, 保存图片到相册, 与图片的上下文菜单“应用程序...”和“共享...”关联, 与 Windows Phone 的图片中心集成
- 将图片保存在iPhone的相册中
- iphone开发——保存图片到相册及容错处理
- Monotouch Save Image To Application(保存相册图片到你的应用程序)
- 将图片保存在iPhone的相册中
- Java+MySql图片数据保存与读取的具体实例
- IOS调取摄像头和相册并保存图片
- JS实现的相册图片左右滚动完整实例