iOS 系统相机调可自定义相机内部图片文字

释放双眼,带上耳机,听听看~!
  1. 遵守代理
    <UIImagePickerControllerDelegate,UIAlertViewDelegate,UIActionSheetDelegate,UINavigationControllerDelegate>

    2.

     UIAlertController * alertVC = [UIAlertController alertControllerWithTitle:@"图片获取方式" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //相机
            if(![XXHelper isCapturePermissionGranted]){
                NSString* info=@"没有相机权限";
                NSLog(@"%@",info);
                return;
            }
            
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                UIImagePickerController * picker = [[UIImagePickerController alloc] init];
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                picker.modalPresentationStyle = UIModalPresentationFullScreen;
                if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]){
                    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
                }
                
                picker.mediaTypes = @[(NSString*)kUTTypeImage];
                picker.allowsEditing = YES;//设置可编辑
    //创建叠加层, 可以在系统相机上层+图片啊文字
                
                UIView *overLayView=[[UIView alloc]initWithFrame:CGRectMake( 0,44 , kScreenWidth, kScreenHeight- 164 )];
                overLayView.backgroundColor = kRandomColor;
    
                overLayView.alpha =0.3;
                //取景器的背景图片,该图片中间挖掉了一块变成透明,用来显示摄像头获取的图片;
                
                UIImage *overLayImag=[UIImage imageNamed:@"zhaoxiangdingwei.png"];
            
                
                UIImageView *bgImageView=[[UIImageView alloc]initWithImage:overLayImag];
                
                bgImageView.center = overLayView.center;
                [overLayView addSubview:bgImageView]; 
                
                
                picker.cameraOverlayView=overLayView;
    
                picker.delegate = self;
                [self presentViewController:picker animated:YES completion:nil];
            }else{
                NSLog(@"设备不可用");
            }
            
        }];
        [alertVC addAction:cameraAction];
        
        UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //相册
            if(![XXHelper isAssetsLibraryPermissionGranted]){
                NSString* info=@"没有相册权限";
                //            [self showAlert:info];
                NSLog(@"%@",info);
                return;
            }
            
        
            _labelView.text=@"";
            
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.modalPresentationStyle = UIModalPresentationCurrentContext;
            if([UIImagePickerController isSourceTypeAvailable: picker.sourceType ]) {
                picker.mediaTypes = @[(NSString*)kUTTypeImage];
                picker.delegate = self;
                picker.allowsEditing = NO;
            }
            [self presentViewController:picker animated:YES completion:nil];
    
        }];
        [alertVC addAction:photoAction];
        alertVC.popoverPresentationController.sourceView = self.view;
        alertVC.popoverPresentationController.sourceRect = sender.frame;
        [self presentViewController:alertVC animated:YES completion:^{
            
        }];

    3 .代理方法

    // UIImagePickerControllerDelegate
    
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
        UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        UIImage* upLoadImage = [[image fixOrientation:image] imgCompressed:image targetWidth:300];//将图片压缩成 300以上传服务器
        _imgV.image = upLoadImage;
        
        self.showImageView.image = upLoadImage;
        
        //压缩图片大小
        NSData* imgData = [upLoadImage compressedData];

     

人已赞赏
iOS文章

iOS 限制 UITextField 小数点输入

2019-12-1 14:20:37

iOS文章

如何解决crash" Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[UICTFont intValue]: unrecognized selector sent to instance 0x10244a800' "

2019-12-1 15:55:57

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索