IOS开发 照相机小结一

本文小白 仅供提醒.

IOS照相机的使用

  情况 程序中使用照相机.

 应用:拍摄图片 保存 并且可以切割图片

 类 : JBCroppableView 第三方

  包:  MobileCoreServices

          

#import "JBCroppableView.h"

#import <MobileCoreServices/UTCoreTypes.h>


@property (nonatomic, strong) UIImageView *image;

@property (nonatomic, strong) JBCroppableView *pointsView;

@property (nonatomic, strong) UIImage *storeImage;

    使用:

// 显示

    // 使用照相机的图片在试图中

    _image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];

    _image.userInteractionEnabled = YES;

    [self.view addSubview:_image];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];

    [_image addGestureRecognizer:tap];


// 打开相机

    UIButton *came = [UIButton buttonWithType:UIButtonTypeCustom];

    came.frame = CGRectMake(80, 440, 80, 40);

    [came setTitle:@"打开" forState:UIControlStateNormal];

    came.backgroundColor = [UIColor cyanColor];

    [came addTarget:self action:@selector(cameOpen:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:came];


// 图像纠偏

    UIButton *tip = [UIButton buttonWithType:UIButtonTypeCustom];

    tip.frame = CGRectMake(160, 440, 80, 40);

    [tip setTitle:@"图像纠偏" forState:UIControlStateNormal];

    tip.backgroundColor = [UIColor cyanColor];

    [tip addTarget:self action:@selector(tip:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:tip];

    

    // 存储

    UIButton *cameStore = [UIButton buttonWithType:UIButtonTypeCustom];

    cameStore.frame = CGRectMake(240, 440, 80, 40);

    [cameStore setTitle:@"Store" forState:UIControlStateNormal];

    cameStore.backgroundColor = [UIColor cyanColor];

    [cameStore addTarget:self action:@selector(storeImage:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:cameStore];


// 可以循环创建UIButton


   使用 系统自带的UIImagePickerController

- (void)cameOpen:(UIButton *)button

{

    // 创建图片选择器

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

    //判断是否可以打开相机

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        //摄像头 指定源的类型

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

        

        picker.delegate = self;

        picker.allowsEditing = YES//是否可编辑

        

        // 推出

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

    }else{

        //如果没有提示用户

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"你没有摄像头" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:nil];

        [alert show];

    }

}


//用户点击图像选取器中的“cancel”按钮时被调用,这说明用户想要中止选取图像的操作

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    [picker dismissViewControllerAnimated:YES completion:nil];

    

}


//用户点击选取器中的“choose”按钮时被调用,告知委托对象,选取操作已经完成,同时将返回选取图片的实例

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

{


    // 显示图片  图片显示在视图中

    [_image setImage:image];


    // 使用第三方类 创建剪切点

    self.pointsView = [[JBCroppableView alloc] initWithImageView:self.image];


    [self.pointsView addPoints:8];

   

    [picker dismissModalViewControllerAnimated:YES];

}



// 截取图片的形状

- (void)tip:(UIButton *)tipButton

{


    // 截取的UIImageView大小

    self.image.frame = [JBCroppableView scaleRespectAspectFromRect1:CGRectMake(0, 0, self.image.frame.size.width, self.image.frame.size.height) toRect2:self.image.frame];

    

    

     [self.view addSubview:self.pointsView];

    

    self.image.image = [self.pointsView deleteBackgroundOfImage:self.image];

 


}


// 存贮图片到相册

- (void)storeImage:(UIButton *)button

{

    

    UIImageWriteToSavedPhotosAlbum(self.storeImage, nil, nil,nil);

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"存储照片成功"

                                                    message:@"您已将照片存储于图片库中,打开照片程序即可查看。"

                                                   delegate:self

                                          cancelButtonTitle:@"OK"

                                          otherButtonTitles:nil];

    [alert show];


    

}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值