IOS调取系统摄像头
2015-10-25 00:32
393 查看
1、打开摄像头 - (IBAction)Open:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { picker.sourceType = UIImagePickerControllerSourceTypeCamera; NSArray *temp_MediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType]; picker.mediaTypes = temp_MediaTypes; picker.delegate = self; picker.allowsImageEditing = YES; } [self presentModalViewController:picker animated:YES]; [picker release]; } 2.拍照回调 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; if ([mediaType isEqualToString:@"public.image"]){ UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; NSLog(@"found an image"); NSString *imageFile = [documentsDirectory stringByAppendingPathComponent:@"temp.jpg"]; NSLog(@"%@", imageFile); success = [fileManager fileExistsAtPath:imageFile]; if(success) { success = [fileManager removeItemAtPath:imageFile error:&error]; } imageView.image = image; [UIImageJPEGRepresentation(image, 1.0f) writeToFile:imageFile atomically:YES]; //SETIMAGE(image); //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]); } else if([mediaType isEqualToString:@"public.movie"]){ NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; NSLog(@"%@", videoURL); NSLog(@"found a video"); NSData *videoData = [NSData dataWithContentsOfURL:videoURL]; /****************************************/ NSString *videoFile = [documentsDirectory stringByAppendingPathComponent:@"temp.mov"]; NSLog(@"%@", videoFile); success = [fileManager fileExistsAtPath:videoFile]; if(success) { success = [fileManager removeItemAtPath:videoFile error:&error]; } [videoData writeToFile:videoFile atomically:YES]; //CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]); //NSLog(videoURL); } [picker dismissModalViewControllerAnimated:YES]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissModalViewControllerAnimated:YES]; }
相关文章推荐
- IOS调取系统摄像头
- iOS中的正则表达式
- iOS7+系统自带条码扫描
- ios CAEmitterCells学习文档
- xamarin IOS C#
- iOS 页面间传值 之 属性传值,代理传值
- iOS——instancetype浅析
- IOS NSDateFormatter 自定义 格式
- iOS激情详解之Core Data
- iOS开发11-iOS 数据持久化(简单、复杂对象的读写)
- Please try rebooting and reconnecting the device. (0xE8000076) xcode7 ios 9.02
- iOS开发10-iOS SandBox(沙盒或沙盘)介绍、路径获取
- iOS || ISO
- 蓝懿ios 技术内容和心得 10。24
- iOS——LLVM、Clang浅析
- IOS开发-C基础2
- iOS NSUserDefaults 之最简单存取数据 小Demo
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十)