从ipad相机相册读取相片并保存
以下是从实际项目中截取的例子,从一个button中启动获得相片
-(IBAction)blumbtnTap:(id)sender
{
// 判断是否支持相机
// UIAlertView *alertview;
// if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
// {
// alertview=[[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"相册选择",@"相机拍照", nil];
// alertview.tag=859;
// [alertview show];
// [alertview release];
// }
// else {
//
// alertview=[[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"相册选择", nil];
// alertview.tag=859;
// [alertview show];
// [alertview release];
// }
UIActionSheet *sheet; // 判断是否支持相机
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
sheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"拍照",@"从相册选择", nil];
}
else { sheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"从相册选择", nil];
} sheet.tag = ; [sheet showInView:self.view]; } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==) {//取消 }
else if (buttonIndex==)//相册选择
{ }
else if (buttonIndex==)//相机拍照
{ }
NSLog(@"%d",buttonIndex);
}
#pragma mark - actionsheet delegate
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == ) { NSUInteger sourceType = ; // 判断是否支持相机
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { switch (buttonIndex) {
case :
// 取消
return;
case :
// 相机
sourceType = UIImagePickerControllerSourceTypeCamera;
break; case :
// 相册
sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
}
}
else {
if (buttonIndex == ) {
return;
} else {
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
}
// 跳转到相机或相册页面
UIImagePickerController *m_imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
m_imagePicker.sourceType = sourceType; //UIImagePickerControllerSourceTypePhotoLibrary;
m_imagePicker.delegate = self;
[m_imagePicker setAllowsEditing:NO];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:m_imagePicker];
popoverController = popover;
[popoverController presentPopoverFromRect:CGRectMake(, , , ) inView:self.
view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"Error accessing photo library!"
delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
} #pragma mark - 保存图片至沙盒
- (void) saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
// 获取沙盒目录
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
// 将图片写入文件
[imageData writeToFile:fullPath atomically:NO];
} #pragma mark - image picker delegte
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{}]; UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
ColorData *acolor=[GoodslistDataCls.colorList objectAtIndex:(currentSelectTag-DETAILDISHINFOVIEWSTARTTAG)];
NSString *imgName=[NSString stringWithFormat:@"%@_%@.png",GoodslistDataCls.goodInfo.goodscode,acolor.colorcode];
[self saveImage:image withName:imgName]; NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imgName]; UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath]; isFullScreen = NO;
[imgView setImage:savedImage];
imgView.tag = ; [popoverController dismissPopoverAnimated:YES]; DishInfoView *aDishInfoView=(DishInfoView *)[self.view viewWithTag:(currentSelectTag)];
aDishInfoView.lblName.textColor=[UIColor redColor];
aDishInfoView.imgView.image=[self readImagewithName:imgName]; [delegate loadDishInfoImg:self.myTag];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:^{}];
}
从ipad相机相册读取相片并保存的更多相关文章
- Swift3.0生成二维码、扫描二维码、相册读取二维码,兼容iOS7(结合ZXingObjC)
二维码生成 //MARK: 传进去字符串,生成二维码图片(>=iOS7) text:要生成的二维码内容 WH:二维码高宽 private func creatQRCodeImage(text: ...
- iOS开发小技巧--相机相册的正确打开方式
iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...
- iOS-iOS调用相机调用相册【将图片保存到本地相册】
设置头部代理 <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 1.调用相机 检测前置摄像头是否可用 - ...
- IOS调用相机相册
#import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...
- 009android初级篇之APP中使用系统相机相册等集成应用
android应用中使用相机功能,大致有两种方式实现: 直接调用系统内部的相机程序,显示的也是系统预设的界面(简单,只有简单的拍照功能): 自己去implement一个相机程序(不难,较具备弹性,但相 ...
- Java从网络读取图片并保存至本地
package cn.test.net; import java.io.File; import java.io.FileOutputStream; import java.io.InputStrea ...
- iOS10 相机相册等权限的使用、检测并引导用户开启权限
<!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能访问 ...
- Python配合BeautifulSoup读取网络图片并保存在本地
本例为Python配合BeautifulSoup读取网络图片,并保存在本地. BeautifulSoup可代替正则表达式,更好地解析Html文本,获取其中的指定内容,如Tag.Property等 # ...
- Java--多线程读取网络图片并保存在本地
本例用到了多线程.时间函数.网络流.文件读写.正则表达式(在读取html内容response时,最好不要用正则表达式来抓捕html文本内容里的特征,因为服务器返回的多个页面的文本内容不一定使用相同的模 ...
随机推荐
- GitHub上整理的一些资料(转)
技术站点 Hacker News:非常棒的针对编程的链接聚合网站 Programming reddit:同上 MSDN:微软相关的官方技术集中地,主要是文档类 infoq:企业级应用,关注软件开发领域 ...
- system2之:4-LVM逻辑卷管理
LVM有扩容功能,无容错功能 物理卷: [root@localhost ~]# pvscan PV /dev/sda2 VG VolGroup lvm2 [19.51 GiB / 0 ...
- 朴素贝叶斯(naive bayes)算法及实现
处女文献给我最喜欢的算法了 ⊙▽⊙ ---------------------------------------------------我是机智的分割线----------------------- ...
- Python爬取CSDN博客文章
0 url :http://blog.csdn.net/youyou1543724847/article/details/52818339Redis一点基础的东西目录 1.基础底层数据结构 2.win ...
- 关于无光盘无u盘状态下该如何安装系统
看到好东西,跟大家分享一下,需要装系统的可以作为参考资料 无光盘无u盘状态下该如何安装系统 重点 : 安装虚拟光驱(用来打开镜像文件) 一个你要安装的系统文件的iso镜像文件 http://www. ...
- (使用步骤)ThinkPHP3.1.2中如何配置Ckeditor_4.1.1和Ckfindtor(转)
ThinkPHP3.1.2中如何配置Ckeditor_4.1.1和Ckfindtor 一.下载Ckeditor和Ckfinder Ckeditor官网 http://ckeditor.com/dow ...
- mxGraph实现按住ctrl键盘拖动图形实现复制图形功能
实现这个功能很easy,仅仅须要重写moveCells方法就能够了.以下是源文件里的代码: mxGraph.prototype.moveCells = function(cells, dx, dy, ...
- Delphi下实现全屏快速找图找色
前言 最近有好几个朋友都在问我找图找色的问题,奇怪?于是乎写了一个专门用于找图找色的单元文件“BitmapData.pas”.在这个单元文件中我实现了从文件中导入位图.屏幕截图.鼠标指针截图.在图片上 ...
- android 17 activity生命周期
手机指南针传感器处于手机头部. Activity生命周期: 启动. onCreat()方法:初始化布局对象,设置监听器. onstart()方法:注册监听器. onResume():activity已 ...
- java解析xml文件四种方式
1.介绍 1)DOM(JAXP Crimson解析器) DOM是用与平台和语言无关的方式表示XML文档的官方W3C标准.DOM是以层次结构组织的节点或信息片断的集合.这个层次结构允许开发人员在树中寻找 ...