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的文章好久都木有更新了,今天更新一篇哈. 这篇文章主要学习 ...
随机推荐
- Windows Update 的工具
Windows Update MiniTool 是一款管理 Windows Update 的工具,可以取得微軟 Windows 修補程式更新包,Windows Update 是我們用來升級系統的元件, ...
- [Web Analytics] Into to Web Analytics
Just to get started for myself. Any developer who doesn't care about the business is not a good soft ...
- VBS 操作Word
VBS 操作Word 1.新建Word文档 '使用Add方法 Dim ObjWD,ObjDOC Set ObjWD=CreateObject("Word.application" ...
- 【bzoj1034】[ZJOI2008]泡泡堂BNB
贪心 将双方的选手均按从强到弱排序,然后第一次扫描尽可能用当前剩下的选手中能赢对手当前最强选手中最弱的一个去赢得胜利,若无法做到,则暂时不考虑给对方最强的选手匹配对手.第二遍扫描使用同样策略去获取尽量 ...
- linux之安装软件出现Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)解决总结
sudo rm -rf /var/lib/dpkg/lock sudo rm -rf /var/cache/apt/archives/lock
- Android6.0源码分析之录音功能(一)【转】
本文转载自:http://blog.csdn.net/zrf1335348191/article/details/54949549 从现在开始一周时间研究录音,下周出来一个完整的博客,监督,激励!!! ...
- java 基础 —— 文件操作(File)
1. 基本成员: File.separator public class File implements Serializable, Comparable<File> { private ...
- IDEA 的使用(快捷键、括号对齐的方式)
Java IDE 工具不是只有一个 Eclipse,还有同样十分优秀的 IDEA. 0. 常用快捷键 查看与设置:[File]⇒ [Settings]⇒ [Keymap] back/forward:c ...
- Wedding(2-SAT)
传送门 稍微复杂一点的2-SAT. 读题之后发现有以下限制: 1.每一对夫妻(包括新郎和新娘)不能坐在桌子的一侧. 2.对于一些给定的非法(自行脑补)的关系,这两个人不能坐在新娘的同一侧. 因为每个人 ...
- vue 基础知识 随笔
window.localStorage.gettItem("someItem"||[])//如果localStorage中的someItem不存在就返回一个空数组 window.l ...