当前位置: 首页 > 编程日记 > 正文

访问系统相册或调用摄像头

头文件:#import <MobileCoreServices/MobileCoreServices.h>

协议:<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

// 调用系统相册获取图片

- (IBAction)getImageFromAlbum:(id)sender {
// 判断系统相册是否可用(比如用户不允许应用访问他的相册,就不可用)
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
[self loadImagePickerControllerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
} else {
NSLog(@"无法调用系统相册");
}
}
// 拍照
- (IBAction)takePhoto:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[self loadImagePickerControllerWithSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
NSLog(@"无法调用相机功能");
}

}
- (void)loadImagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)type {
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.sourceType = type;
    controller.delegate = self; // <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
    controller.allowsEditing = YES;
    [self presentViewController:controller animated:YES completion:nil];
}


#pragma mark - <UIImagePickerControllerDelegate>
// 选完图片时回调
/**
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {}
 */

// 选完媒体资源【(图片)(小视频)】时回调
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // 判断选中的资源的类型
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    
    // kUTTypeImage 系统预置的图片资源类型
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
        // self.view.backgroundColor = [UIColor colorWithPatternImage:image];
        
        // 将原图压缩成50*50的尺寸
        UIImage *smallImage = [[ImageTool shareTool] resizeImageToSize:CGSizeMake(300,300) sizeOfImage:image];
        self.view.backgroundColor = [UIColor colorWithPatternImage:smallImage];
    }
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}

// 取消【点击cancel的时候触发】
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:nil];
}

相关文章:

unity镜像_通过镜像学习Unity Multiplayer Basics

unity镜像Unity is one of the most well-known and established engines for game development, and Mirror is a third-party, open source networking solution that allows you to add multiplayer to your games.Unity是最著名的游戏开发引擎之一&#xff0c;而Mirror是第…

java内存模型和线程安全

转载于:https://www.cnblogs.com/Michael2397/p/8397451.html

测试,发布,质量保障,用户体验

1.在实际项目中何时开始设计用户体验&#xff1a;用户的第一印象&#xff1b;从用户的角度考虑问题&#xff1b;软件啊服务始终要记住用户的选择&#xff1b;短期刺激和长期影响 2.测试经验交流&#xff1a;基本名词解释及分类&#xff1b;按测试设计的方法分类&#xff1b;按测…

UIImage存为本地文件与UIImage转换为NSData

UIImage *image"XXX"; //png格式 NSData *imagedataUIImagePNGRepresentation(image); //JEPG格式 //NSData *imagedataUIImageJEPGRepresentation(image); NSArray*pathsNSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString …

如何在JavaScript中实现链接列表

If you are learning data structures, a linked list is one data structure you should know. If you do not really understand it or how it is implemented in JavaScript, this article is here to help you. 如果您正在学习数据结构&#xff0c;则链表是您应该知道的一种…

SVG.path_不连续的线段

1、之前 用<path/>画的 线段等 都是连续的&#xff0c;想知道 是否能画 不连续的线段等 结论&#xff1a;可以 2、测试代码&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <svg width"1000" height"800" viewBo…

Leetcode 之Binary Tree Postorder Traversal(44)

后序遍历&#xff0c;比先序和中序都要复杂。访问一个结点前&#xff0c;需要先判断其右孩子是否被访问过。如果是&#xff0c;则可以访问该结点&#xff1b;否则&#xff0c;需要先处理右子树。 vector<int> postorderTraversal(TreeNode *root){vector<int> resu…

如何创建自己的ESLint配置包

ESLint is a powerful tool that helps you enforce consistent coding conventions and ensure quality in your JavaScript codebase. ESLint是一个功能强大的工具&#xff0c;可帮助您实施一致的编码约定并确保JavaScript代码库的质量。 Coding conventions are sometimes …

MySQL更新命令_UPDATE

创建测试表 mysql> CREATE TABLE product (-> proID int(11) NOT NULL AUTO_INCREMENT COMMENT 商品表主键,-> price decimal(10,2) NOT NULL COMMENT 商品价格,-> type int(11) NOT NULL COMMENT 商品类别(0生鲜,1食品,2生活),-> dtime datetime N…

KVC与KVO

1、键值编码KVC常用的KVC操作方法如下&#xff1a;• 动态设置&#xff1a; setValue:属性值 forKey:属性名&#xff08;用于简单路径&#xff09;、setValue:属性值 forKeyPath:属性路径&#xff08;用于复合路径&#xff0c;例如Person有一个Account类型的属性&#xff0c…

javaScript 工作必知(三) String .的方法从何而来?

String 我们知道javascript 包括&#xff1a;number&#xff0c;string&#xff0c;boolean,null,undefined 基本类型和Object 类型。 在我的认知中&#xff0c;方法属性应该是对象才可以具有的。 var str"hello,world";var sstr.subString(1,4);//ellalert(typeof…

s3 aws_您需要了解的有关AWS S3的所有信息

s3 awsThis article will provide an in-depth introduction to AWS S3 — the secure, scalable, and super cheap storage service from Amazon Web Services.本文将深入介绍AWS S3-来自Amazon Web Services的安全&#xff0c;可扩展和超便宜的存储服务。 If you have eve…

untitled与前端——初学

“前端” 啥&#xff1f; 百度百科&#xff1a; 就是制作一网页界面。比如360浏览器打开&#xff0c; 包括界面布局设计&#xff0c;搜索框&#xff0c;点击字或图标跳到另一个页面等。 软件Untitled 下载网址&#xff1a;http://www.jetbrains.com/ 下拉 点download&#xff0…

NSThread

NSThread是轻量级的多线程开发&#xff0c;使用起来也并不复杂&#xff0c;但是使用NSThread需要自己管理线程生命周期。 可以使用对象方法&#xff1a; (void)detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)argument 直接将操作添加到线程中并…

异步发送邮件、短信、微信

用户创建订单的按钮点击后&#xff0c;服务器存储这个订单信息后&#xff0c;调用发送短信、邮件、微信的接口&#xff0c;发送消息。而发送短信、邮件、微信都要涉及第三方的处理&#xff0c;服务器又要发送一个新的包裹给一个新的服务器&#xff0c;告诉他帮我发一个信息出去…

英语面试简短问题_用简单的英语解释产品设计

英语面试简短问题Product design is the process you go through when you conceptualize and build a product.产品设计是概念化和构建产品时要经历的过程。 The path to building – hardware, software, or even simple prototypes – has different steps and approaches.…

6-12 二叉搜索树的操作集

6-12 二叉搜索树的操作集&#xff08;30 分&#xff09; 本题要求实现给定二叉搜索树的5种常用操作。 函数接口定义&#xff1a; BinTree Insert( BinTree BST, ElementType X ); BinTree Delete( BinTree BST, ElementType X ); Position Find( BinTree BST, ElementType X );…

iOS关于自定义rightBarButtonItem

在常见iOS开发中,我们常遇到这样的需求,如下: 我们需要自定义导航栏右侧按钮,常见的自定义包装按钮如下: //设置rightItem; UIButton *btn [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame CGRectMake(0, 0, 40, 30); btn.selected NO; [btn setTitle:"管理&…

URL里汉字转码

URL里面不能包含中文。 解决办法&#xff1a;进行转码 NSString *urlStr[NSString stringWithFormat:kLotteryBar_putOutReviewUrl,_token,self.reviews_id,_User_Id,reviews_content]; urlStr[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

electron.js_在使用Electron.js之前我希望知道的事情

electron.jsIn this article, Ill share how you can avoid some of the mistakes I made when learning about Electron.js &#x1f926;‍♂️. I hope it helps!在本文中&#xff0c;我将分享如何避免在学习Electron.js &#x1f926;‍&#x1f926;️时犯的一些错误。 希…

Entity Framework的启动速度优化

最近开发的服务放到IIS上寄宿之后&#xff0c;遇到一些现象&#xff0c;比如刚部署之后&#xff0c;第一次启动很慢&#xff1b;程序放置一会儿&#xff0c;再次请求也会比较慢。比如第一个问题&#xff0c;可以解释为初次请求某一个服务的时候&#xff0c;需要把程序集加载到内…

NSURLConnection的简单使用

遵循代理&#xff1a;NSURLConnectionDataDelegate -(void)fetchWebData:(id)sender{ self.isLoadingYES;NSString *urlStrkRequestUrlStr(self.page);NSURL *url[NSURL URLWithString:urlStr];NSURLRequest *request[NSURLRequest requestWithURL:url];self.connection[N…

tcp reno_如何使用称为Reno Expo的简单入门工具包构建全栈应用程序

tcp renoBuilding any new project from scratch can be intimidating. Theres a lot to decide before you can even start coding to test out your idea.从头开始构建任何新项目都可能令人生畏。 在开始编码以检验您的想法之前&#xff0c;还有很多决定。 How are you buil…

不同命名空间的对象二进制反序列化问题

本质上说&#xff0c;这并不是二进制序列化的问题&#xff0c;甚至不关序列化的问题。 你想要的是在两个内部结构一致但在不同命名空间&#xff08;甚至不同项目&#xff09;的同名类间做类型转换。 这个问题很常见&#xff0c;因为实际工作中经常会有此类需求&#xff0c;但是…

对大文件的断点续传

注&#xff1a;#import "YGFileDownloader.h"是对NSURLConnection的简单封装 #import "YGResumeDownloadViewController.h" #import "NSStringutil.h"#import "YGFileDownloader.h"#define URL "http://dlsw.baidu.com/sw-searc…

bootstrap modal 弹出效果

window.showMsg function (msg) {//显示悬浮窗$("#autoCloseModal").modal("show")//设置文本内容$("#autoCloseModal #autoCloseModalBody").html("")$("#autoCloseModal #autoCloseModalBody").html(msg);//两秒后消失se…

68-95-99规则–以普通英语解释正态分布

Meet Mason. Hes an average American 40-year-old: 5 foot 10 inches tall and earning $47,000 per year before tax.认识梅森。 他平均年龄40岁&#xff0c;身高5英尺10英寸&#xff0c;每年税前收入$ 47,000。 How often would you expect to meet someone who earns 10x …

Uva 10048 - Audiophobia (Floyd变形)

题目链接 https://vjudge.net/problem/UVA-10048 【题意】 输入一个C个点&#xff0c;S个边&#xff08;C<100,S<1000&#xff09;的无向图&#xff0c;边权表示该路径上的噪声值&#xff0c;当你从某点出发到另外一点时希望路上经过的最大噪声值最小&#xff0c;输入一…

ubuntu联网经常掉线的解决方法

打开电脑&#xff0c;发现联网的图标没有连接上&#xff0c;想手动点击连接上&#xff0c;却发现选项是灰色&#xff08;不可选&#xff09; 或者是图标显示已经连接上了&#xff0c;但浏览器就是无法上网&#xff0c;也ping不通 此时打开终端输入 sudo /etc/init.d/network-ma…

JSON和XML

JSONJSON(JavaScript Object Notation)一种轻量级的数据交换格式&#xff0c;具有良好的可读和便于快速编写的特性。可在不同平台之间进行数据交换。JSON采用兼容性很高的、完全独立于语言文本格式&#xff0c;同时也具备类似于C语言的习惯(包括C, C, C#, Java, JavaScript, Pe…