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];

     

标签:

未经允许不得转载:作者:SheaYang, 转载或复制请以 超链接形式 并注明出处 技术狗|博客
原文地址:《iOS 系统相机调可自定义相机内部图片文字》 发布于2019-12-01

分享到:
赞(0)

评论 抢沙发

9 + 3 =


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

长按图片转发给朋友

Vieu4.0主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录