iOS从手机相册选择一张照片并显示 Objective-C
要先给app设置访问相册的权限:
在项目的Info.plist文件里添加Privacy - Photo Library Usage Description权限
ViewController.h:
#import <UIKit/UIKit.h> @interface ViewController : UIViewController
{
IBOutlet UIImageView *myImageView; //与ImageView视图关联
} - (IBAction)buttonUp:(id)sender; // 与一个Button关联 @end
ViewController.m:
#import "ViewController.h"
@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>//接口
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonUp:(id)sender {
//初始化UIImagePickerController类
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
//判断数据来源为相册
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
//设置代理
picker.delegate = self;
//打开相册
[self presentViewController:picker animated:YES completion:nil];
}
//选择完成回调函数
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
//获取图片
UIImage *image = info[UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
myImageView.image = image;
}
//用户取消选择
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
iOS从手机相册选择一张照片并显示 Objective-C的更多相关文章
- iOS 从手机相册里选取图片
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- iOS 调用系统相册 相机 时,显示中文标题
解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed YES 表示是否允许应用程序 ...
- 【ARK UI】HarmonyOS 从相册选择图片并显示到Image组件上
参考资料 [Harmony OS][ARK UI]ETS 上下文基本操作 [Harmony OS][ARK UI]ets使用startAbility或startAbilityForResult方式 ...
- MUI - IOS系统,相册选择照片后,点击确定按钮无反应
MUI框架下使用 plus.gallery.pick 时,选择好照片之后,点击确定按钮无反应(既没报错,也没正确执行成功或失败后的回调方法).这是在做测试时,其中有两台苹果机上出现的bug.做了调试也 ...
- Android 拍照或相册选择照片进行显示缩放位图 Demo
拍照后直接使用 BitmapFactory.decodeStream(...) 进行创建 Bitmap 并显示是有问题的. Bitmap 是个简单对象,它只存储实际像素数据,也就是说,即使原始照片已压 ...
- IOS调用相机相册
#import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...
- 相册选择头像或者拍照 上传头像以NSData 图片二进制格式 表单上传
一.点击头像图片 或者按钮 在相册选择照片返回img,网络上传头像要用data表单上传 (1)上传头像属性 // 图片二进制格式 表单上传 @property (nonatomic, strong) ...
- IOS研究院之打开照相机与本地相册选择图片
如下图所示 在本地相册中选择一张图片后,我们将他拷贝至沙盒当中,在客户端中将它的缩略图放在按钮旁边,这个结构其实和新浪微薄中选择图片后的效果一样.最终点击发送将按钮将图片2进制图片上传服务器. 下面我 ...
- IOS研究院之打开照相机与本地相册选择图片(六)
原创文章如需转载请注明:转载自雨松MOMO程序研究院本文链接地址:IOS研究院之打开照相机与本地相册选择图片(六) Hello 大家好 IOS的文章好久都木有更新了,今天更新一篇哈. 这篇文章主要学习 ...
随机推荐
- 怎样把UCos-ii_在STM32上的移植
下载代码 stm32 标准外设库是 stm32 全系列芯片的外设驱动,有了它能够大大加速我们 开发 stm32. 首先从 st 公司的站点下载最新的 stm32 标准外设库,写本文时最新的版本号是 V ...
- Creating A Simple Web Server With Golang
原文:https://tutorialedge.net/post/golang/creating-simple-web-server-with-golang/ -------------------- ...
- 011 router backup
Router>en Router#config t Enter configuration commands, one per line. End with CNTL/Z. Router(co ...
- 安装Nginx须要系统的辅助软件(linux)
安装Nginx须要系统的辅助软件(linux): yum -y install make gcc gcc-c++ ncurses-devel yum -y install zlib zlib-deve ...
- SEO 搜索引擎优化培训01
百度搜索风云榜:http://top.baidu.com/boards 页面上的因素:对搜索引擎而言
- Paypal支付(一)MPL真正的快捷支付
一.前导 前面讲到了MEC支付,是在Web端集成好的,在手机端仅仅需通过WebView进行载入就可以,不须要不论什么Paypal第三方架包.以下将的是MPL支付.须要架包. 这样的支付的形式能够參考以 ...
- grep 并列查询 效率 且 或
find / | grep -v python | grep -v xl_ | grep -v xiaole |grep redis [root@hadoop3 ~]# find / | grep - ...
- Linux ALSA声卡驱动之一:ALSA架构简介【转】
本文转载自:http://blog.csdn.net/droidphone/article/details/6271122 声明:本博内容均由http://blog.csdn.net/droidpho ...
- leetcode 258. Add Digits——我擦,这种要你O(1)时间搞定的必然是观察规律,总结一个公式哇
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- POJ1279 Art Gallery 多边形的核
POJ1279 给一个多边形 求它的核的面积 所谓多边形的核 是多边形中的一个点集 满足其中的点与多边形边上的点的连线全部在多边形中 用多边形的每一条边所在的直线去切整个坐标平面 得到的一个凸包就是核 ...