首页 > 其他 > 详细

保存到相册

时间:2016-04-18 01:08:48      阅读:205      评论:0      收藏:0      [点我收藏+]
@interface ViewController ()
void UIImageWriteToSavedPhotosAlbum (
                               
                                     UIImage  * image,
                                  
                                     id      completionTarget,
                                  
                                     SEL      completionSelector,
                                  
                                     void    *contextInfo
                                 
                                     );
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
   
    UIImage *imagName = [UIImage imageNamed:@"submit"];
   
    [self saveImageToPhotos:imagName];
}


-(void)saveImageToPhotos:(UIImage*)savedImage

{
  
    UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
 
}

// 指定回调方法

- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo

{
 
    NSString *msg = nil ;
 
    if(error != NULL){
   
        msg = @"保存图片失败" ;
      
    }else{
     
        msg = @"保存图片成功" ;
     
    }
   
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存图片结果提示"
                      
                                                    message:msg
                      
                                                   delegate:self
                         
                                          cancelButtonTitle:@"确定"
                     
                                          otherButtonTitles:nil];
  
    [alert show];
   
}
 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

     if([touch tapCount] == 1)

     {

       NSLog(@"single click %@",[imageView image]);

       UIImageWriteToSavedPhotosAlbum([imageView image], nilnil,nil);

       UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"存储照片成功"

                                                 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定义的方法上。一般是当完成后调用方法时使用,或者在完成时出错的处理。

保存到相册

原文:http://www.cnblogs.com/hangman/p/5402883.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!