• 保存到相册


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

    一天一章
  • 相关阅读:
    利用WebClient实现自动添写、提交表单
    动态.net代码生成器遇到的问题
    unicode
    使用using清理非托管资源
    C#中解决插入数据库的某个字段类型为datetime 为空
    JQuery中根据属性或属性值获得元素
    Access 的top和order by 的问题
    JavaScript escape() 函数
    Asp.net嵌套
    合并程序集时出错的问题ILMerge.Merge.ERROR...
  • 原文地址:https://www.cnblogs.com/hangman/p/5402883.html
Copyright © 2020-2023  润新知