访问相册, 从相册中选取图片

@interface OneViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>{

UIImageView *imageView;

}

@end

@implementation OneViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor yellowColor];

//UIImageView 继承于UIView

imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 150)];

imageView.backgroundColor = [UIColor grayColor];

[self.view addSubview:imageView];

UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];

button.frame = CGRectMake(100, 200, 100, 100);

button.layer.cornerRadius = 50;

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

[button setTitle:@"相机" forState:(UIControlStateNormal)];

[self.view addSubview:button];

button.backgroundColor = [UIColor redColor];

UIButton *mButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

mButton.frame = CGRectMake(50, 400, 100, 50);

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

mButton.backgroundColor = [UIColor redColor];

[mButton setTitle:@"相册" forState:(UIControlStateNormal)];

[self.view addSubview:mButton];

}

- (void)camera {

//判断是否由摄像头

BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:(UIImagePickerControllerCameraDeviceRear)];

//UIImagePickerControllerCameraDeviceRear后置摄像头

//前置摄像头UIImagePickerControllerCameraDeviceFront

if (!isCamera) {

NSLog(@"没有后置摄像头");

return;

}

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

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

imagePicker.delegate = self;

imagePicker.editing = YES;//相机照的照片是否允许编辑

[self presentViewController:imagePicker animated:YES completion:^{

}];

}

//调取相册

- (void)photo {

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

imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:imagePicker animated:YES completion:^{

NSLog(@"打开系统相册");

}];

imagePicker.delegate = self;

[imagePicker release];

}

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

//选取相册照片

imageView.image = image;

[self dismissViewControllerAnimated:YES completion:^{

}];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

时间: 2024-12-24 20:19:02

访问相册, 从相册中选取图片的相关文章

判断是否有权限访问相机,相册,定位

1.判断用户是否有权限访问相册 #import <AssetsLibrary/AssetsLibrary.h> ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus]; if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied) { //无权限 } typedef enum { kCLAuthori

android 7.0+ FileProvider 访问隐私文件 相册、相机、安装应用的适配

从 Android 7.0 开始,Android SDK 中的 StrictMode 策略禁止开发人员在应用外部公开 file:// URI.具体表现为,当我们在应用中使用包含 file:// URI 的 Intent 离开自己的应用时,程序会发生FileUriExposedException 异常 这里我们要使用到的 FileProvider,就是 ContentProvider 的一个特殊子类,帮助我们将访问受限的 file:// URI 转化为可以授权共享的 content:// URI.

相册选取图片和照相机取图片

选取图片可以从设备图片库或者从照相机抓取,系统为我们提供的类UIImagePickerController就是一个图像选择器. UIImagePickerController的主要属性是sourceType,其定义如下 按顺序说明: UIImagePickerControllerSourceTypePhotoLibrary 为相簿 UIImagePickerControllerSourceTypeCamera        为照相机 UIImagePickerControllerSourceTy

查询是否有权限访问相机和相册

+(BOOL)getSystemPhotoAuthority { BOOL agree=NO; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if(authStatus == AVAuthorizationStatusAuthorized||authStatus == AVAuthorizationStatusNotDetermined)

桑德菲杰没能形成新相册你相册

http://www.l99.com/EditText_view.action?textId=8155905 http://www.l99.com/EditText_view.action?textId=8155907 http://www.l99.com/EditText_view.action?textId=8155908 http://www.l99.com/EditText_view.action?textId=8155909 http://www.l99.com/EditText_vi

iOS之SQLite中的查询与排序 访问手机相册 向手机相册中存图

Day05 SQLite中的查询与排序 按查询结果排序:[[email protected][NSSortDescriptor sortDescriptorWithKey:@"age"ascending:yes]]; 设置查询条件: NSPredicate  *pre=nil; 1.比较运算符 > <  >=  <= == != pre=[NSPridicate [email protected]“age>40”]; 2. 范围运算符 IN  BETWEE

iOS 下的相册与图片处理

iOS 下的相册与图片处理 需求 很多公司项目中都会使用到相册,以及相机,保存图片,从相册中选取图片等等操作.本文将详细介绍该功能如何实现优化,以及使用一些优秀的第三方库来辅助完成我们的需求. photos framework 的使用 Photos Framework reference Classes PHAdjustmentData /* When a user edits an asset, Photos saves a PHAdjustmentData object along with

安卓实现二维码生成和扫描功能,扫描支持直接拍照扫码和相册图片扫码,还加了照明功能

最近在做二维码的生成和扫描,生成二维码相对而言较为简单,扫描相对复杂,遇到的问题较多,但是在实现二维码的生成和扫描之前最重要的一步 就是讲Zxing包导入,后面的内容大部分是使用包中的内容, 那我就从二维码的生成讲起吧! 二维码生成: 直接贴代码了 1 //要转换的地址或字符串,可以是中文,输入内容生成二维码 2 public Bitmap createQRImage(String string) { 3 try { 4 Hashtable<EncodeHintType, String> hi

Android--利用相机或相册截取用户头像(解决了miui无法截取,以及部分机型拍照无返回Uri)

声明 本文的Demo可用于从本地获取用户头像时使用,解决了有些手机系统相机拍照后获取不到拍摄照片的问题,以及解决小米miui系统调用系统裁剪图片功能camera.action.CROP后崩溃或重新打开app的问题. 修改了部分机型拍照后返回的是缩略图的临时文件的问题. 如何获得一张原图 先看代码: UtilClass.requestPermission(ChangeMyDataActivityCopy.this, android.Manifest.permission.CAMERA); choo