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

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

作者: WS_0909 | 来源:发表于2017-06-01 15:55 被阅读0次
  1. 遵守代理
<UIImagePickerControllerDelegate,UIAlertViewDelegate,UIActionSheetDelegate,UINavigationControllerDelegate>
 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 系统相机调可自定义相机内部图片文字

    遵守代理 3 .代理方法

  • iOS自定义相机

    iOS自定义相机的实现 本文主要介绍iOS系统上的自定义相机的实现,其实并不难主要包含了,拍摄设备,输入端,输出端...

  • 技术集合

    相机开发 iOS开发--AVFoundation自定义相机 iOS视频播放AVPlayer的视频内容拉伸设置 状态...

  • Android自定义相机

    CustomCamera android自定义相机 功能描述: 主要可自定义相机的各类按钮布局 相机拍照缩放功能 ...

  • Android摄像头基础(一)

    在App中使用Camera的两种方式 调用系统相机、或者是具有相机功能的应用 自定义相机 调用系统相机 调用系统相...

  • 13.4 camera

    简介 android中相机使用有两种方式,一是调用系统相机(Intent),二是自定义相机 调用系统相机相册 自定...

  • iOS 之自定义相机

    项目最近要用到相机,但是界面自己设计了,所以系统相机就使不上了。所以研究了下自定义相机。 因为自定义相机的API在...

  • 自己写一个Android照相机应用(2)

    自定义相机 上一篇讲的是调用系统相机拍照然后显示在屏幕上,自定义一个相机就是自己相机的activity。1,首先是...

  • iOS模仿系统相机拍照你不曾注意过的细节

    iOS模仿系统相机拍照你不曾注意过的细节 iOS模仿系统相机拍照你不曾注意过的细节

  • iOS自定义相机

    iOS自定义相机 我们选择拍照的时候,系统提供了一个UIImagePickerController,但是功能太弱,...

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/gnrefxtx.html