照相机 相册 以及相册的使用

1 照相机的使用

1) 控制器的使用 UIImagePickerController 

   7.0系统判断相机是否有使用权限

NSString *mediaType = AVMediaTypeVideo;

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];

if(authStatus == ALAuthorizationStatusRestricted || authStatus == ALAuthorizationStatusDenied) {

// 相机权限问题界面 (判断是相机还是相册)

}

跳转页面 

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

pickImage.sourceType = UIImagePickerControllerSourceTypeCamera;// 类型 

pickImage.delegate = self;

[self.view.window.rootViewController presentViewController:pickImage animated:YES completion:nil];


拍照完的方法

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    [picker dismissViewControllerAnimated:YES completion:nil];

    UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];// 拍摄完毕 保存图片

}


2 相册的使用

1) 相机是否可以使用

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) { 

        CLAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

        if (status == ALAuthorizationStatusRestricted || status == ALAuthorizationStatusDenied) {


        }

    }

 

2)获取相册的图片

ALAssetsLibrary * lib = [[ALAssetsLibrary alloc]init];

[lib enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

        // 获取相册列表

        if(group != nil){

         

            NSString * groupName = [group valueForProperty:ALAssetsGroupPropertyName];// 相册名字


            libraryData.albumName = groupName;

            libraryData.posterImage = group.posterImage;

            NSMutableArray * photoArray = [[NSMutableArray alloc]init];

            [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {// 相册照片列表

                if(result!= nil){

                    NSString * assetType = [result valueForProperty:ALAssetPropertyType];

                    if([assetType isEqualToString:ALAssetTypePhoto]){

                        [photoArray addObject:result];

                    }else if([assetType isEqualToString:ALAssetTypeVideo]){

                        

                    }else if ([assetType isEqualToString:ALAssetTypeUnknown]){

                        

                    }

                }

            }];

            

            if(photoArray.count > 0)

            {

                libraryData.group = group;

                libraryData.photoArray = photoArray;

                // 存放图片

                if ([groupName isEqualToString:@"相机胶卷"]) {

                    [self.photoLibrary insertObject:libraryData atIndex:0];

                } else {

                    [self.photoLibrary addObject:libraryData];

                }

            }

        }

// init tableview

    } failureBlock:^(NSError *error) {


    }];


3)处理图片

可以添加通知来存放图片


-(void)selectImageFromPhotoLibraryFinishNotification:(NSNotification *)sender

{

    if([[sender object] isKindOfClass:[NSMutableArray class]]){

        NSMutableArray * array = (NSMutableArray *)[sender object];

        for (ALAsset * asset in array) {

// 获取图片

            ALAssetRepresentation * representation =  asset.defaultRepresentation;

            CGImageRef imageref = [representation fullScreenImage];

            UIImage * image = [UIImage imageWithCGImage:imageref];

            

            if ([image isKindOfClass:[UIImage class]]) {

           

            }

        }

    }

    [[NSNotificationCenter defaultCenter] removeObserver:self name:NOTIFICATION_MYPHOTO_LIBRARY_BACK object:nil];

}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值