保存图片到IPhone图片库中
2013-06-30 12:52
155 查看
有时候需要将应用中的图片保存到用户iPhone或者iTouch的相册中。 可以使用UIKit的这个类方法来完成。
比如可以这样来写一个存储图片的方法:
回调方法:
截取屏幕图片可以这样:
void UIImageWriteToSavedPhotosAlbum ( UIImage *image, // 要保存到用户设备中的图片 id completionTarget, //可选的参数,当保存完成后,回调方法所在的对象 SEL completionSelector, //可选的参数,当保存完成后,所调用的回调方法。 void *contextInfo //可选的参数,保存了一个指向context数据的指针,它将传递给回调方法。 );
比如可以这样来写一个存储图片的方法:
// 要保存的图片 UIImage *img = [UIImage imageNamed:@"ImageName.png"]; // 保存图片到相册中 UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 可以在保存图片的时候加个动画: CATransition* animation = [CATransition animation]; [animation setType:@"suckEffect"]; [animation setDuration:0.5f]; [animation setTimingFunction:UIViewAnimationCurveEaseInOut]; //self.view.opaque = 1.0f; [self.view.layer addAnimation:animation forKey:@"animationEffect"]; [self.view.layer removeAnimationForKey:@"animationEffect"];
回调方法:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { //错误处理 if (error != NULL) { // Show error message... } else { //保存图片成功 // Show message image successfully saved } }
截取屏幕图片可以这样:
-(UIImage *)imageFromView:(UIView *)theView { UIGraphicsBeginImageContext(CGSizeMake(320, theView.frame.size.height)); CGContextRef context = UIGraphicsGetCurrentContext(); [theView.layer renderInContext:context]; UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage; }
相关文章推荐
- 从 iPhone/iPad 图片库中读取图片的代码
- iPhone/iOS图片相关(读取、保存、绘制、其它相关)
- iphone把图片保存到“照片”功能实现
- 将图片保存在iPhone的相册中
- iphone UIImageWriteToSavedPhotosAlbum 保存图片
- iPhone/iOS图片读取、保存、绘制
- 将图片保存在iPhone的相册中
- iPhone/iOS图片相关(读取、保存、绘制、其它相关)
- iphone UIImageWriteToSavedPhotosAlbum 保存图片
- unity3d 保存(截图、拍照)图片 到Android IPhone手机相册
- iPhone应用程序 将图片保存到相册实例
- (Metro学习三)图片uri保存到本地图片库
- 保存图片到相册 iphone UIImageWriteToSavedPhotosAlbum 保存图片
- iphone three20 保存本地的图片
- 及时能在图片库中显示保存的图片
- iphone/ipad保存图片问题
- iPhone开发笔记(12)利用.net实现服务端接收上传的图片并保存
- iphone/ipad保存图片问题(已解决)
- Win8 图片uri保存到本地图片库 -- 及各种流之间的转换
- 将图片保存在iPhone的相册中