IOS开发 照相机小结一

本文介绍了一个iOS应用程序如何利用系统相机拍摄图片,并通过第三方库JBCroppableView进行图片裁剪及编辑,最后保存到设备相册的功能实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文小白 仅供提醒.

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


    

}






内容概要:本文档详细介绍了个基于多任务学习(MTL)结合Transformer编码器的多变量时间序列预测项目。该项目旨在解决多变量时间序列预测中的复杂性、长序列依赖、任务间干扰等问题,通过融合多任务学习与Transformer架构,构建了套高效且可扩展的预测系统。项目覆盖了从环境准备、数据预处理、模型构建与训练、性能评估到GUI界面设计的完整流程,并提供了详细的代码实现。模型采用多头自注意力机制有效捕捉变量间及时间维度上的复杂依赖,通过多任务共享层和任务特异性层实现任务间知识共享与个性化特征提取。此外,项目还引入了动态任务权重调整、轻量化设计、数据预处理优化等关键技术,确保模型在实际应用中的高效性和准确性。 适合人群:具备定编程基础,特别是对深度学习和时间序列分析有定了解的研发人员和技术爱好者。 使用场景及目标:① 提升多变量时间序列预测的准确率;② 实现高效的时间序列特征提取;③ 促进多任务学习在时间序列领域的应用推广;④ 提供可扩展的模型架构设计,适应不同应用场景的需求;⑤ 降低模型训练与推断的计算资源需求;⑥ 促进复杂系统的智能决策能力,如智能制造、能源管理、金融分析、气象预报等领域的精准预测支持。 其他说明:项目不仅提供了完整的代码实现和详细的文档说明,还设计了用户友好的GUI界面,方便用户进行数据加载、参数设置、模型训练及结果可视化等操作。未来改进方向
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值