zoukankan      html  css  js  c++  java
  • 保存到相册

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

    一天一章
  • 相关阅读:
    项目踩坑实记 :2019年(SSM 架构)
    多线程实践
    SpringCloud(一)之我学 Eureka
    JVM 第一次学习总结 --- 2019年4月
    《深入理解 JVM 虚拟机》 --- 看书笔记
    JVM 学习(二)Java 内存模型、方法内联、逃逸 --- 2019年4月
    JVM 学习(一)反射、垃圾回收、异常处理--- 2019年4月
    剑指offer-18.树的子结构
    剑指offer-17.合并两个有序链表
    剑指offer-16.翻转链表
  • 原文地址:https://www.cnblogs.com/hangman/p/5402883.html
Copyright © 2011-2022 走看看