码迷,mamicode.com
首页 > 其他好文 > 详细

拍照/相册/录像/本地视频

时间:2016-08-23 23:35:42      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

1.导入系统库

#import <MobileCoreServices/MobileCoreServices.h>

2.遵守协议

<UIImagePickerControllerDelegate,UINavigationControllerDelegate>

3.创建

#pragma mark 相机--拍照

- (void)openCamera{

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

    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;

    ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

    ipc.allowsEditing = YES;

    ipc.delegate = self;

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

    

    

}

#pragma mark 录像

- (void)openVideo{

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

    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;

    ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];

    ipc.videoQuality = UIImagePickerControllerQualityTypeHigh;

    ipc.allowsEditing = YES ;

    ipc.delegate = self;

    

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

    

}

 

 

#pragma mark  相册

- (void)openPhoto{

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

    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

    ipc.allowsEditing = YES;

    ipc.delegate = self;

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

    

}

#pragma mark  本地视频

- (void)openVideoList{

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

    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];

    ipc.allowsEditing = YES;

    ipc.delegate = self;

    

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

    

}

 

 4.代理方法 

#pragma mark --Delegate 拍完后执行

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

    if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeImage]) {

        //拍照与获取本地相册

        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

        self.fileData = UIImageJPEGRepresentation(image, 1.0);

        self.imageView.image = image;

        

    }else if ([[info objectForKey: UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]){

        //录像与获取本地视频

        NSString *videoPath = [info objectForKey:UIImagePickerControllerMediaURL];

        self.fileData = [NSData dataWithContentsOfFile:videoPath];

        

        NSLog(@"%@",self.fileData);

        

    }

       [picker dismissViewControllerAnimated:YES completion:nil];

}

 

#pragma mark --Delegate 功能取消

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

    

    [picker dismissViewControllerAnimated:YES completion:nil];

    

}

 

 

 

 

 

 

 

拍照/相册/录像/本地视频

标签:

原文地址:http://www.cnblogs.com/daxueshan/p/5801181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!