以下是从实际项目中截取的例子,从一个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. UVa11526 H(n)

    http://blog.csdn.net/synapse7/article/details/12873437 #include<cstdio> #include<cstring> ...

  2. winform 窗体最大化 分类: WinForm 2014-07-17 15:57 215人阅读 评论(0) 收藏

    1:窗体首次加载时最大化 (1):主窗体 this.WindowState = FormWindowState.Maximized; //窗体显示中间部分,不显示窗体名称和最小化.最大化.关闭按钮   ...

  3. wikioi 2573 大顶堆与小顶堆并用

    题目描写叙述 Description 我们使用黑匣子的一个简单模型.它能存放一个整数序列和一个特别的变量i.在初始时刻.黑匣子为空且i等于0. 这个黑匣子能运行一系列的命令.有两类命令: ADD(x) ...

  4. IIS注册.net框架及temp文件权限开放

    配置好IIS服务之后,在浏览器打开localhost:xx[端口号],提示:无法识别属性 targetFramework=4.0 这是因为项目是4.0框架,配置IIS时,在应用程序池没有选择.net ...

  5. 关于git status

    如果只在本地修改,还没有commit,那么用git status, 打印信息为: 如果我本地没有修改文件,就是:

  6. Unity3D 相机跟随主角移动

    这里给主相机绑定一个脚本. 脚本写为: using UnityEngine; using System.Collections; public class camerafollow : MonoBeh ...

  7. 玩javaweb的web.xml编译路径

    有时候能够碰到这样的情况 缓存就是 清不掉 那就可以去寻找编译路径了 <Context docBase="E:\java-workspace\eigyo_com405" pa ...

  8. Linux 查看系统硬件信息(实例详解)

    原文链接:http://www.cnblogs.com/ggjucheng/archive/2013/01/14/2859613.html linux查看系统的硬件信息,并不像windows那么直观, ...

  9. Android屏幕图标尺寸规范

    http://blog.csdn.net/dyllove98/article/details/9174229 . 程序启动图标:ldpi (120 dpi)小屏mdpi (160 dpi)中屏hdpi ...

  10. wpf 调用线程必须为sta 因为许多ui组件都需要

    解决 办法 public void SomeMethod() { var task = System.Windows.Application.Current.Dispatcher.BeginInvok ...