以下是从实际项目中截取的例子,从一个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相机相册读取相片并保存的更多相关文章

  1. Swift3.0生成二维码、扫描二维码、相册读取二维码,兼容iOS7(结合ZXingObjC)

    二维码生成 //MARK: 传进去字符串,生成二维码图片(>=iOS7) text:要生成的二维码内容 WH:二维码高宽 private func creatQRCodeImage(text: ...

  2. iOS开发小技巧--相机相册的正确打开方式

    iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...

  3. iOS-iOS调用相机调用相册【将图片保存到本地相册】

    设置头部代理 <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 1.调用相机 检测前置摄像头是否可用 - ...

  4. IOS调用相机相册

    #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...

  5. 009android初级篇之APP中使用系统相机相册等集成应用

    android应用中使用相机功能,大致有两种方式实现: 直接调用系统内部的相机程序,显示的也是系统预设的界面(简单,只有简单的拍照功能): 自己去implement一个相机程序(不难,较具备弹性,但相 ...

  6. Java从网络读取图片并保存至本地

    package cn.test.net; import java.io.File; import java.io.FileOutputStream; import java.io.InputStrea ...

  7. iOS10 相机相册等权限的使用、检测并引导用户开启权限

    <!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能访问 ...

  8. Python配合BeautifulSoup读取网络图片并保存在本地

    本例为Python配合BeautifulSoup读取网络图片,并保存在本地. BeautifulSoup可代替正则表达式,更好地解析Html文本,获取其中的指定内容,如Tag.Property等 # ...

  9. Java--多线程读取网络图片并保存在本地

    本例用到了多线程.时间函数.网络流.文件读写.正则表达式(在读取html内容response时,最好不要用正则表达式来抓捕html文本内容里的特征,因为服务器返回的多个页面的文本内容不一定使用相同的模 ...

随机推荐

  1. JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式(转)

    需求如下 现有数据列三列 Name,Age,CreateDate 数据 张三,18,2000-12-09 :12:34:56 李四,28,2000-12-09 :12:34:56 王麻子,38,200 ...

  2. bzoj3907: 网格

    http://www.cnblogs.com/Tunix/p/4354348.html #include<cstdio> #include<cstring> #include& ...

  3. iOS开发雕虫小技之傻瓜式定位神器-超简单方式解决iOS后台定时定位

    1.概述 由于公司一款产品的需求,最近一直在研究iOS设备的后台定位.主要的难点就是,当系统进入后台之后,程序会被挂起,届时定时器.以及代码都不会Run~ 所以一旦用户将我的App先换到了后台,我的定 ...

  4. MySQL (DCL)

    DCL语句 :数据库系统管理员使用,也就是数据库管理员 root 可以添加用户.删除用户.授予和限制用户权限,这些用户的信息可以在数据库的mysql数据库中查询到 1.查看用户信息     1.用ro ...

  5. 《31天成为IT服务达人》之精准运维

     1       第十四章精准运维服务 近年来国内IT产业的发展格局始终与我国的经济转型与创新创业的社会大潮息息相关,纵观国内国际形势,IT产业仍是创新的领头者,是解决人类各种经济危机的主要扮演者 ...

  6. Android中fragment_main.xml文件里的组件获取的问题

    package com.dhy.phonedial; import android.app.Activity; import android.app.Fragment; import android. ...

  7. SQL Server手工插入标识列

    如果我们在标识列中插入值,例如: insert member(id,username) values(10,'admin') 则在查询分析器里面会返回错误信息: 引用内容 服务器: 消息 544,级别 ...

  8. [RxJS] Combination operator: combineLatest

    While merge is an OR-style combination operator, combineLatest is an AND-style combination operator. ...

  9. android 56

    ##其他布局 * LinearLayout * RelativeLayout * FrameLayout * AbsoluteLayout (绝对布局, 文档说过时,应用场景机顶盒开发,定制的平板) ...

  10. Building Tomcat7 source step by step---官方文档

    Table of Contents Introduction Download a Java Development Kit (JDK) version 6 Install Apache Ant 1. ...