======================================================================================

#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调用相机相册的更多相关文章

  1. iOS调用相机,相册,上传头像

    一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...

  2. iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏

    一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...

  3. ios调用系统相册、相机 显示中文标题、本地化多语言支持

    因为调用系统相册.相机需要显示中文,所以搞了半天才知道是在Project->info->Custom ios Target Properties 添加 Localizations 并加入C ...

  4. IOS调用相机和相册时无法显示中文

    调用系统相册.相机发现是英文的系统相簿界面后标题显示“photos”,但是手机语言已经设置显示中文 需要在info.plist做如下设置 info.plist里面添加 Localizedresourc ...

  5. iOS调用系统相册、相机 显示中文标题

    解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed          YES 表 ...

  6. iOS 调用系统相册 相机 时,显示中文标题

    解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed YES 表示是否允许应用程序 ...

  7. H5-安卓和ios调用相机和相册

    <input v-if="ipshow" type="file" accept="image/*" name="file1& ...

  8. cordova+vue打包ios调用相机闪退解决

    cordova+vue项目打包android,打开相机正常使用,但是打包ios后,需要多几个配置,才能打开,否则当调用的时候会闪退,上配置图 需要在选中的文件里面添加 <key>NSCam ...

  9. ios 调用相机后 view 下沉问题

    我只加了一句代码 现在不报错了  因为这个问题是随机性的  我也不太明白这个地方是怎么回事   我只是这样子做了  问题不出来了 if ([[[UIDevice currentDevice] syst ...

随机推荐

  1. 【转】istringstream、ostringstream、stringstream 类介绍 .

    http://www.cnblogs.com/gamesky/archive/2013/01/09/2852356.html 好吧,懒死我算了

  2. Android之ORMLite实现数据持久化的简单使用

    Android中内置了sqlite,但是常用的开发语言java是面向对象的,而数据库是关系型的,二者之间的转化每次都很麻烦.(作为程序员,应该学会偷懒)而Java Web开发中有很多orm框架(其实我 ...

  3. ios自动滚动图片功能源码

    源码AdScrollerView,一个已经封装好的UIScrollView的子类,可以自动滚动图片以及对应的描述语,类似淘宝app首页的广告滚动效果.滚动图片数量不限,并且显示pageControl. ...

  4. 理解CPU内存管理

    概述:从设计层面理解CPU的内存模式,包括段式内存管理.页式内存管理以及虚拟化扩展内存管理.实际上,硬件支持与软件实现从来就不是能分开讲的,比如,Intel CPU架构师在选择CPU的硬件特性时,必然 ...

  5. ubuntu下使用vi是方向键变乱码 退格键不能使用的解决方法

    ubuntu下使用vi是方向键变乱码 退格键不能使用的解决方法 转载:http://blog.csdn.net/yao_qinwei/article/details/8761777 在插入模式下,按删 ...

  6. Sql Server 维护计划 备份覆盖

            之前在设置服务器Sql Server 维护计划 备份的sql server 数据库,都是累加的,后来也没有仔细看过,后台回过头来考虑到服务器的存储空间,只好做sql server 数据 ...

  7. 抽象类[abstract]_C#

    抽象类(abstract) abstract修饰符可以和类.方法.属性.索引器及事件一起使用.在类声明中使用abstract修饰符以指示某个类只能是其它类的基类.标记为抽象或包含在抽象类中的成员必须通 ...

  8. (转)Mysql数据库读写分离配置

    环境模拟 实现读写分离 减轻数据库的负荷 主服务器 master 10.0.0.12从服务器 slave 10.0.0.66 ------------------------------------- ...

  9. poj 3046 Ant Counting

    Ant Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4982   Accepted: 1896 Desc ...

  10. FKCL-OS——自主的操作系统

    我想搞一个操作系统,这是因为我对windows非常不满意,对linux非常讨厌,我想要开发一个真正自己的OS,然后让自己和别人使用它.得到方便.我将在这篇文章中写下我对操作系统的不满,然后构思出我的操 ...