拍照沙漠行军蚁经过后照片选照片是工作人员的外水吗

程序写累了,就来玩玩酷跑小游戏吧,嘿嘿。
雨松MOMO送你一首歌曲,嘿嘿。
IOS研究院之打开照相机与本地相册选择图片(六)
IOS研究院之打开照相机与本地相册选择图片(六)
围观76065次
编辑日期: 字体:
Hello 大家好 IOS的文章好久都木有更新了,今天更新一篇哈。 这篇文章主要学习如何在IOS程序中打开照相机与本地相册并且选择一张图片。还是老样子MOMO写了一个简单的测试程序,如下图所示 在本地相册中选择一张图片后,我们将他拷贝至沙盒当中,在客户端中将它的缩略图放在按钮旁边,这个结构其实和新浪微薄中选择图片后的效果一样。最终点击发送将按钮将图片2进制图片上传服务器。
下面我们仔细学习具体的细节。创建一个空的IOS项目,接着在创建一个ViewController。
AppDelegate.h 应用的代理类 这个没什么好说的就是直接打开刚刚创建的新ViewController。
#import &UIKit/UIKit.h&#import "TestViewController.h"&@interface AppDelegate : UIResponder &UIApplicationDelegate&&@property (strong, nonatomic) UIWindow *window;@property (strong, nonatomic) UINavigationController *navController;@property (strong, nonatomic) UIViewController *viewController;@end
AppDelegate.m 在这里就是打开我们创建的TestViewController
12345678910111213141516171819202122232425262728
#import "AppDelegate.h"&@implementation AppDelegate&@synthesize window = _window;@synthesize navController;@synthesize viewController;&- (void)dealloc{&&&&[_window release];&&&&[super dealloc];}&- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{&&&&self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];&&&&&self.window.backgroundColor = [UIColor whiteColor];&&&&self.viewController =&&[[TestViewController alloc]init];&&&&self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];&&&&[self.window addSubview:navController.view];&&&&&[self.window makeKeyAndVisible];&&&&return YES;}&@end
TestViewController.h 注意这里面引入了很多代理类。
1234567891011121314
#import &UIKit/UIKit.h&&@interface TestViewController : UIViewController&UITextViewDelegate,UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate&{&&&&//输入框&&&&UITextView *_textEditor;&&&&&//下拉菜单&&&&UIActionSheet *myActionSheet;&&&&&//图片2进制路径&&&&NSString* filePath;}@end
TestViewController.m 请大家仔细看这个类, 所有的东西都写在了这里哈。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
#import "TestViewController.h"&@interface TestViewController ()&@end&@implementation TestViewController&- (void)viewDidLoad{&&&&[super viewDidLoad];&&&&//导航栏标题 self.navigationItem.title = @"雨松MOMO输入框";&&&&&//导航栏按钮&&&&self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& initWithTitle: @"发送"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& style: UIBarButtonItemStyleDone&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& target: self&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& action: @selector(sendInfo)] autorelease];&&&&&//输入框显示区域&&&&_textEditor = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];&&&&//设置它的代理&&&&_textEditor.delegate = self;&&&&_textEditor.autoresizingMask = UIViewAutoresizingFlexibleWidth;&&&&_textEditor.keyboardType = UIKeyboardTypeDefault;&&&&_textEditor.font = [UIFont systemFontOfSize:20];&&&&_textEditor.text = @"请输入内容";&&&&&//默认软键盘是在触摸区域后才会打开&&&&//这里表示进入当前ViewController直接打开软键盘&&&&[_textEditor becomeFirstResponder];&&&&&//把输入框加在视图中&&&&[self.view addSubview:_textEditor];&&&&&//下方的图片按钮 点击后呼出菜单 打开摄像机 查找本地相册&&&&UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"camera" ofType:@"png"]];&&&&&UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];&&&&button.frame = CGRectMake(0, 120, image.size.width, image.size.height);&&&&&[button setImage:image forState:UIControlStateNormal];&&&&&[button addTarget:self action:@selector(openMenu) forControlEvents:UIControlEventTouchUpInside];&&&&&//把它也加在视图当中&&&&[self.view addSubview:button];&}&-(void)openMenu{&&&&//在这里呼出下方菜单按钮项&&&&myActionSheet = [[UIActionSheet alloc]&&&&&&&&&&&&&&&& initWithTitle:nil&&&&&&&&&&&&&&&& delegate:self&&&&&&&&&&&&&&&& cancelButtonTitle:@"取消"&&&&&&&&&&&&&&&& destructiveButtonTitle:nil&&&&&&&&&&&&&&&& otherButtonTitles: @"打开照相机", @"从手机相册获取",nil];&&&&&&&[myActionSheet showInView:self.view];&&&&[myActionSheet release];&&&&&}&- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ &&&&&//呼出的菜单按钮点击后的响应&&&&if (buttonIndex == myActionSheet.cancelButtonIndex)&&&&{&&&&&&&&NSLog(@"取消");&&&&}&&&&&switch (buttonIndex)&&&&{&&&&&&&&case 0:&&//打开照相机拍照&&&&&&&&&&&&[self takePhoto];&&&&&&&&&&&&break; &&&&&&&&&case 1:&&//打开本地相册&&&&&&&&&&&&[self LocalPhoto];&&&&&&&&&&&&break;&&&&}}&//开始拍照-(void)takePhoto{&&&&UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;&&&&if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])&&&&{&&&&&&&&UIImagePickerController *picker = [[UIImagePickerController alloc] init];&&&&&&&&picker.delegate = self;&&&&&&&&//设置拍照后的图片可被编辑&&&&&&&&picker.allowsEditing = YES;&&&&&&&&picker.sourceType = sourceType;&&&&&&&&[picker release];&&&&&&&&[self presentModalViewController:picker animated:YES];&&&&}else&&&&{&&&&&&&&NSLog(@"模拟其中无法打开照相机,请在真机中使用");&&&&}}&//打开本地相册-(void)LocalPhoto{&&&&UIImagePickerController *picker = [[UIImagePickerController alloc] init];&&&&&picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;&&&&picker.delegate = self;&&&&//设置选择后的图片可被编辑&&&&picker.allowsEditing = YES;&&&&[self presentModalViewController:picker animated:YES];&&&&[picker release];}&//当选择一张图片后进入这里-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info&{&&&&&NSString *type = [info objectForKey:UIImagePickerControllerMediaType];&&&&&//当选择的类型是图片&&&&if ([type isEqualToString:@"public.image"])&&&&{&&&&&&&&//先把图片转成NSData&&&&&&&&UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];&&&&&&&&NSData *data;&&&&&&&&if (UIImagePNGRepresentation(image) == nil)&&&&&&&&{&&&&&&&&&&&&data = UIImageJPEGRepresentation(image, 1.0);&&&&&&&&}&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&data = UIImagePNGRepresentation(image);&&&&&&&&}&&&&&&&&&//图片保存的路径&&&&&&&&//这里将图片放在沙盒的documents文件夹中&&&&&&&&NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];&&&&&&&&&&&//文件管理器&&&&&&&&NSFileManager *fileManager = [NSFileManager defaultManager];&&&&&&&&&//把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png&&&&&&&&[fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];&&&&&&&&[fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];&&&&&&&&&//得到选择后沙盒中图片的完整路径&&&&&&&&filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath,&&@"/image.png"];&&&&&&&&&//关闭相册界面&&&&&&&&[picker dismissModalViewControllerAnimated:YES];&&&&&&&&&//创建一个选择后图片的小图标放在下方&&&&&&&&//类似微薄选择图后的效果&&&&&&&&UIImageView *smallimage = [[[UIImageView alloc] initWithFrame:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CGRectMake(50, 120, 40, 40)] autorelease];&&&&&&&&&&&&&smallimage.image = image;&&&&&&&&//加在视图中&&&&&&&&[self.view addSubview:smallimage];&&&&&} &}&- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{&&&&NSLog(@"您取消了选择图片");&&&&[picker dismissModalViewControllerAnimated:YES];}&-(void)sendInfo{&&&&NSLog(@"图片的路径是:%@", filePath);&&&&&NSLog(@"您输入框中的内容是:%@", _textEditor.text);}&- (void)viewDidUnload{&&&&[super viewDidUnload];&&&&// Release any retained subviews of the main view.}&- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{&&&&return (interfaceOrientation == UIInterfaceOrientationPortrait);}&@end
如下图所示,打开下拉菜单按钮开始选择打开相机 或者 打开本地相册。模拟器中是无法打开照相机的的,切记。
如下图所示,这里就是我本地的相册啦,里面保存了几张图片,选择一张即可。
我在这里再说说图片上传, 图片上传我们采用的是2进制ASIHTTPRequest 来完成的。
123456789101112131415
&&&&NSString *server_base = [NSString stringWithFormat:@"%@/users/uploadResource.json", _server];&&&&&ASINetworkQueue *queue = [[ASINetworkQueue alloc] init];&&&&&&&ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:server_base]];&&&&&[ASIHTTPRequest setShouldUpdateNetworkActivityIndicator: NO];&&&&[request setDelegate :self];&&&&[request setDidFinishSelector:@selector(sendCommentSucc:)];&&&&[request setDidFailSelector:@selector(sendCommentFail:)];&&&&// res 就是 需要上传图片文件的路径&&&&[request setFile:res forKey:@"res"];&&&&&[queue addOperation:request];&&&&[queue go];
最后是文本的源码,雨松MOMO祝大家学习愉快,不早了,我也得睡觉啦,1点多了。。。
下载地址:
本文固定链接:
转载请注明:
雨松MOMO提醒您:亲,如果您觉得本文不错,快快将这篇文章分享出去吧 。另外请点击网站顶部彩色广告或者捐赠支持本站发展,谢谢!
作者:雨松MOMO
专注移动互联网,Unity3D游戏开发
如果您愿意花10块钱请我喝一杯咖啡的话,请用手机扫描二维码即可通过支付宝直接向我捐款哦。
您可能还会对这些文章感兴趣!女模水下拍照身亡 有多年潜水经验却意外呛水 | 北晚新视觉ios一个类似微信朋友圈发消息的弹窗(包括拍照摄像和从相册选择照片)
刚开博客,第一次写,准备记录和分享下我自己学到并写的一些技术和应用。
闲话不说,我先大致介绍下,这个控件大致就和微信中朋友圈发消息的那个弹窗,感觉这个很实用,就试着去写了,然后后面又加上了拍照录像和从相册中选图片的功能。拍照和录像用的是UIImagePickerController,都是系统的,主要精力是花在了自制的相册,从系统相册中读取照片和相册并显示。
在写之前我就想着要开博客写文章了,所以我把在写的时候遇到的问题和我认为需要注意的地方都记了下来。
& & 注意:
&1.点击按钮后是在整个view上加一个view,背景设灰色半透明,再从下面推出一个buttonView放按钮,用setTransform作动画。
&2.在取消选择时,有两种方式:一种是点在buttonView下面加的取消按钮;另一种是点除了buttonView的其它地方(方式是给整个加上的view加个点击手势)。
1.在把弹出选择的按钮视图时,因为存在导航栏,所以要把这个视图加到self.navigationController.view上而不是在self.view,这样可以让导航栏也暗掉。
2.因为弹出的选择视图不确定(在已经选择照片的时候要把摄像按钮隐藏),所以要把按钮名字从外部传参数进来,动态决定按钮数。
3.在选择照片界面,因为要点击cell中的按钮来选择,我通过按钮的selected属性来判断图片是否选择。然后通过代理,改变“已选择”图片数组。
& 附上预览图:
&&后面我还会继续完善,可能写的不好欢迎和我交流=。=
& 最后附上github地址:
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。女模水下拍照身亡 卸下氧气管意外呛水
  |  来源: 中国网  |  作者:  |  责任编辑: 王静
  女模水下拍照身亡 卸下氧气管意外呛水
台湾25岁模特顾思妤15日下午在后壁湖出水口海域潜水时,发生呛水意外,被救起后旁人紧急进行心肺复苏术(CPR),消防人员到场后赶紧将她送医急救,不过到院时已无生命迹象,经过急救后仍宣告不治,确切死因仍待检警调查。
5月16日报道据台湾媒体报道,25岁的伊林模特儿的顾思妤昨天下午在后壁湖出水口海域进行水下拍摄时意外呛水,被随行人员救起后,送医时已无生命迹象,经急救仍告不治。确切死因待检警进一步相验。顾女的脸书好友“你回来好不好”、“不能相信”等留言,显示相当不舍。
1              
中国政协频道 新闻热线/商务合作:010-  传真:010-  合作QQ:
版权所有 中国互联网新闻中心 电话: 86-10- 京ICP证 040089号
网络传播视听节目许可证号:0105123 京公网安备号 京网文[5号
| 法律顾问: |
| 对外服务:

我要回帖

更多关于 沙漠行军蚁经过后照片 的文章

 

随机推荐