IOS调用相机相册
======================================================================================
#import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考
#import <MobileCoreServices/UTCoreTypes.h>
@interface SendViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
-(IBAction)selectDescPic:(id)sender;
@end
@implementation SendViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(IBAction)selectDescPic:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"拍照", @"从手机相册选择",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
UIImagePickerController *camera = [[UIImagePickerController alloc] init];
camera.delegate = self;
camera.allowsEditing = NO;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
//此处设置只能使用相机,禁止使用视频功能
camera.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
} else {
NSLog(@"相机功能不可用");
return;
}
[self presentViewController:camera animated:YES completion:nil];
} else if (buttonIndex == 1) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
//从相册列表选取
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
//此处设置只能使用相机,禁止使用视频功能
picker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
}
[self presentViewController:picker animated:YES completion:nil];
} else if(buttonIndex == 2) {
//取消
}
}
@end
=========================================
将图片保存到相册 亲试可用
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 300)];
_imageView.image = [UIImage imageNamed:@"hmt.jpg"];
_imageView.userInteractionEnabled = YES;
[self.view addSubview:_imageView]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[tapGesture addTarget:self action:@selector(tapSaveImageToIphone)];
[self.imageView addGestureRecognizer:tapGesture]; } - (void)tapSaveImageToIphone{ /**
* 将图片保存到iPhone本地相册
* UIImage *image 图片对象
* id completionTarget 响应方法对象
* SEL completionSelector 方法
* void *contextInfo
*/
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{ if (error == nil) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show]; }else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show];
} }
IOS调用相机相册的更多相关文章
- iOS调用相机,相册,上传头像
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
- iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
- ios调用系统相册、相机 显示中文标题、本地化多语言支持
因为调用系统相册.相机需要显示中文,所以搞了半天才知道是在Project->info->Custom ios Target Properties 添加 Localizations 并加入C ...
- IOS调用相机和相册时无法显示中文
调用系统相册.相机发现是英文的系统相簿界面后标题显示“photos”,但是手机语言已经设置显示中文 需要在info.plist做如下设置 info.plist里面添加 Localizedresourc ...
- iOS调用系统相册、相机 显示中文标题
解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed YES 表 ...
- iOS 调用系统相册 相机 时,显示中文标题
解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed YES 表示是否允许应用程序 ...
- H5-安卓和ios调用相机和相册
<input v-if="ipshow" type="file" accept="image/*" name="file1& ...
- cordova+vue打包ios调用相机闪退解决
cordova+vue项目打包android,打开相机正常使用,但是打包ios后,需要多几个配置,才能打开,否则当调用的时候会闪退,上配置图 需要在选中的文件里面添加 <key>NSCam ...
- ios 调用相机后 view 下沉问题
我只加了一句代码 现在不报错了 因为这个问题是随机性的 我也不太明白这个地方是怎么回事 我只是这样子做了 问题不出来了 if ([[[UIDevice currentDevice] syst ...
随机推荐
- 转: utf16编码格式(unicode与utf16联系)
转自: http://www.cnblogs.com/dragon2012/p/5020259.html UTF-16是Unicode字符集的一种转换方式,即把Unicode的码位转换为16比特长的码 ...
- atomikos分布式事务的几个坑
atomikos几个坑:1.jta.properties:com.atomikos.icatch.output_dir=/datayes/atomikoscom.atomikos.icatch.log ...
- android用异步操作AsyncTask编写文件查看器
Activity程序 package com.example.fileasynctaskproject; import java.io.File; import java.util.ArrayList ...
- MyEclipse SVN 插件
一.下载SVN插件subclipse 下载地址:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 在打开的网 ...
- ### C++总结-[类的继承]
面向对象中关于继承的总结. #@author: gr #@date: 2015-07-26 #@email: forgerui@gmail.com 一.类的隐藏 重载(overload).覆盖(ove ...
- 20141015--for语句1
for 语句 break (跳出循环体) 100节楼梯,第1-49节分数等于节数,50以后(包括50)每节10分,
- jqGrid API 全
JQGrid是一个在jquery基础上做的一个表格控件,以ajax的方式和服务器端通信. JQGrid Demo 是一个在线的演示项目.在这里,可以知道jqgrid可以做什么事情. 下面是转自其他人b ...
- 当里个当,免费的HTML5连载来了《HTML5网页开发实例详解》连载(一)
读懂<HTML5网页开发实例详解>这本书 你还在用Flash嘛?帮主早不用了 乔布斯生前在公开信“Flash之我见”中预言:像HTML 5这样在移动时代中创立的新标准,将会在移动设备上获得 ...
- 提升程序的特权(AdjustTokenPrivileges)
首先列出需要的函数 1.OpenProcessToken 2.AdjustTokenPrivileges 3. LookupPrivilegeValue ----------------------- ...
- 在Spring中使用cache(EhCache的对象缓存和页面缓存)
Spring框架从version3.1开始支持cache,并在version4.1版本中对cache功能进行了增强. spring cache 的关键原理就是 spring AOP,通过 spring ...