您的位置:首页 > 其它

将图片保存在本地相册中

2014-03-23 22:04 330 查看
在一个视图中有一个UIImageView,当单击此UIImageView,将UIImageView中的UIImage所代表的图片保存到PhotoAlbum中。

imageView =[[UIImageView alloc]initWithFrame:self.view.bounds];
imageView.image =[UIImage imageNamed:@"1.jpg"];
[self.view addSubview:imageView];
[imageView release];
       
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch =[touches anyObject];
if ([touch tapCount]==1) {
UIImageWriteToSavedPhotosAlbum(imageView.image, nil, nil, nil);
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"存储照片成功" message:@"您已将照片存储于图片库中,打开照片程序即可查看。" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}


UIImageWriteToSavedPhotosAlbum是UIKit框架中的一个函数。

这里说一下后面三个参数的含义:

void UIImageWriteToSavedPhotosAlbum(

   UIImage  *image,

   id       completionTarget,

   SEL      completionSelector,

   void     *contextInfo

);

 

id是target对象,sel是selector,即target对象上的方法名,contextInfo是任意指针,会传递到selector定义的方法上。一般是当完成后调用方法时使用,或者在完成时出错的处理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: