• IOS调用相机相册


    ======================================================================================

    #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考

    #import <MobileCoreServices/UTCoreTypes.h>  

    @interface SendViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>  

    -(IBAction)selectDescPic:(id)sender;  

    @end  

    @implementation SendViewController  

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  

        if (self) {  

        }  

        return self;  

    }  

    - (void)viewDidLoad {  

        [super viewDidLoad];  

    }  

    - (void)didReceiveMemoryWarning {  

        [super didReceiveMemoryWarning];  

    }  

    -(IBAction)selectDescPic:(id)sender {  

        UIActionSheet *actionSheet = [[UIActionSheet alloc]  

                                   initWithTitle:nil  

                                      delegate:self  

                                      cancelButtonTitle:@"取消"  

                                     destructiveButtonTitle:nil  

                                   otherButtonTitles:@"拍照", @"从手机相册选择",nil];  

        actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;  

        [actionSheet showInView:self.view];  

    }  

    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {  

        if (buttonIndex == 0) {  

            UIImagePickerController *camera = [[UIImagePickerController alloc] init];  

            camera.delegate = self;  

            camera.allowsEditing = NO;  

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {  

               camera.sourceType = UIImagePickerControllerSourceTypeCamera;  

            //此处设置只能使用相机,禁止使用视频功能  

                camera.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];  

            } else {  

               NSLog(@"相机功能不可用");  

                return;  

            }  

            [self presentViewController:camera animated:YES completion:nil];  

       } else if (buttonIndex == 1) {  

           UIImagePickerController *picker = [[UIImagePickerController alloc] init];  

            picker.delegate = self;  

            picker.allowsEditing = NO;  

            //从相册列表选取  

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {  

                //此处设置只能使用相机,禁止使用视频功能  

               picker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];  

           }  

            [self presentViewController:picker animated:YES completion:nil];  

        } else if(buttonIndex == 2) {  

            //取消  

        }  

    }  

    @end  

    =========================================

    将图片保存到相册  亲试可用

      - (void)viewDidLoad  
        {  
            [super viewDidLoad];  
            // Do any additional setup after loading the view.  
              
            self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 300)];  
            _imageView.image = [UIImage imageNamed:@"hmt.jpg"];  
            _imageView.userInteractionEnabled = YES;  
            [self.view addSubview:_imageView];  
              
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];  
            tapGesture.numberOfTapsRequired = 1;  
            tapGesture.numberOfTouchesRequired = 1;  
            [tapGesture addTarget:self action:@selector(tapSaveImageToIphone)];  
            [self.imageView addGestureRecognizer:tapGesture];  
          
        }  
          
        - (void)tapSaveImageToIphone{  
          
            /** 
             *  将图片保存到iPhone本地相册 
             *  UIImage *image            图片对象 
             *  id completionTarget       响应方法对象 
             *  SEL completionSelector    方法 
             *  void *contextInfo 
             */  
            UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);  
              
        }  
          
        - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{  
          
            if (error == nil) {  
              
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];  
                [alert show];  
                  
            }else{  
              
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];  
                [alert show];  
            }  
              
        }  
  • 相关阅读:
    在emacs上使用博客园的代码功能
    Programming Pearls笔记之一
    Virtualbox中Archlinux联网问题
    微信公众平台消息接口开发集成解决方案
    发送短信
    基于JMS的数据交换既数据互操作平台的解决方案
    Spring MVC基于注解的Junit测试
    获取设置一个字节某一个位的数值
    NotificationManager
    调用系统联系人列表
  • 原文地址:https://www.cnblogs.com/isItOk/p/4873100.html
Copyright © 2020-2023  润新知