以下是从实际项目中截取的例子,从一个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. UVaLive2572 poj1418 UVa1308 Viva Confetti

    一次放下n个圆 问最终可见的圆的数量 应该是比较经典的问题吧 考虑一个圆与其他每个圆的交点O(n)个 将其割成了O(n)条弧 那么看每条弧的中点 分别向内向外调动eps这个点 则最上面的覆盖这个点的圆 ...

  2. 【设计模式 - 2】之单例模式(Singleton)

    1      模式简介 单例模式在代码中是非常常用的,如线程池.数据库连接.注册表.共享资源.一些非常消耗资源的组件,等等. 单例模式主要解决如下问题: 确保一个特殊类的实例是独一无二的: 确保这个类 ...

  3. IAAS云计算产品畅想-云主机的产品定位

    要研究某个产品的定位,就要先研究一下这个产品进入市场以后会影响了谁,被影响的产品产业,就是你的定位环境. 现例举一下公有云iaas服务影响了谁(按重要程度顺序): 1.企业IT 2.设备厂商 3.数据 ...

  4. 【转】Android通过Wifi来调试你的应用

    http://stormzhang.com/android/2014/08/27/adb-over-wifi/ 在Android中调试我们经常要用一根USB数据线连接到手机和电脑,一方面麻烦不说,手机 ...

  5. 如何在word2007中并排查看对比显示两个文档

    使用word编辑或修改文件时,有时会需要对两个文档进行对比,此时就应该使用并排查看功能. 点击“视图”菜单中的“并排查看” 所打开的两个文档就会同时打开,并排显示 可点击“同步滚动”设置或取消同步滚动

  6. Linux kernel驱动相关抽象概念及其实现 之“linux设备模型kobject,kset,ktype”

    kobject,kset,ktype三个很重要的概念贯穿Linux内核驱动架构,特转载一篇博文: (转载自http://blog.csdn.net/gdt_a20/article/details/64 ...

  7. 【Android】Android的优点和不足之处

    随着Android的越来越红火,不少应聘Android开发的人,难免会被问到这样的问题,就是这个平台的优点,当然有优点也会有缺点的, 下面是我从网上总结出来的,希望对大家应聘Android开发有所帮助 ...

  8. hibernate之增删改查demo

    package dao; import java.util.ArrayList; import java.util.List; import org.hibernate.Query; import o ...

  9. Git CMD - pull: Fetch from and integrate with another repository or a local branch

    命令格式 git pull [options] [<repository> [<refspec>…​]] 命令参数 -q, --quiet 安静模式. -v, --verbos ...

  10. 传统的log4j实战

    /** * */ package log4j; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator ...