ios 通过调用系统摄像头拍照,拍视频,然后写入文件
来源:互联网 发布:淘宝直播 知乎 编辑:程序博客网 时间:2024/04/28 21:49
如果您的App里需要获得由系统自带的照相机、摄像机和录音软件所生成的文件。可以借鉴以下代码来调用iPhone摄像头拍照或者摄像的功能,并把获得的数据直接写入到文件。
//这一段是,点击一个takePicture按钮的操作.
01
- (IBAction)takePicture:(id)sender {
02
03
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
04
05
if
([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
06
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
07
NSArray *temp_MediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
08
picker.mediaTypes = temp_MediaTypes;
09
picker.delegate = self;
10
picker.allowsImageEditing = YES;
11
}
12
13
[self presentModalViewController:picker animated:YES];
14
[picker release];
15
16
}
//下面两个函数是遵守 UIImagePickerControllerDelegate这个协议所实现的类.这样就能够完整的实现,获取照片或者视频,然后写入文件的过程.
01
- (
void
)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
02
{
03
04
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
05
06
BOOL
success;
07
NSFileManager *fileManager = [NSFileManager defaultManager];
08
NSError *error;
09
10
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
11
NSString *documentsDirectory = [paths objectAtIndex:0];
12
13
if
([mediaType isEqualToString:@
"public.image"
]){
14
15
UIImage *image = [info objectForKey:@
"UIImagePickerControllerEditedImage"
];
16
; NSLog(@“found an image”);
17
18
NSString *imageFile = [documentsDirectory stringByAppendingPathComponent:@
"temp.jpg"
];
19
; NSLog(@“%@”, ,imageFile);
20
21
success = [fileManager fileExistsAtPath:imageFile];
22
if
(success) {
23
success = [fileManager removeItemAtPath:imageFile error:>error];
24
}
25
26
imageView.image = image;
27
[UIImageJPEGRepresentation(image, 1.0f) writeToFile:imageFile atomically:YES];
28
29
//SETIMAGE(image);
30
//CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
31
; }
32
else
if
([mediaType isEqualToString:@
"public.movie"
]){
33
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
34
NSLog(@“%@”, ,videoURL);
35
NSLog(@“found a video”);
36
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
37
38
/****************************************/
39
40
NSString *videoFile = [documentsDirectory stringByAppendingPathComponent:@
"temp.mov"
];
41
; NSLog(@“%@”, ,videoFile);
42
43
success = [fileManager fileExistsAtPath:videoFile];
44
if
(success) {
45
success = [fileManager removeItemAtPath:videoFile error:>error];
46
}
47
[videoData writeToFile:videoFile atomically:YES];
48
//CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
49
;
//NSLog(videoURL);
50
}
51
[picker dismissModalViewControllerAnimated:YES];
52
}
53
54
- (
void
)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
55
56
[picker dismissModalViewControllerAnimated:YES];
57
58
}
0 0
- 通过调用系统摄像头拍照,拍视频,然后写入文件
- ios 通过调用系统摄像头拍照,拍视频,然后写入文件
- ios 通过调用系统摄像头拍照,拍视频,然后写入文件
- 通过调用系统摄像头拍照,拍视频,然后写入文件的代码范例.
- 通过调用系统摄像头拍照,拍视频,然后写入文件的代码范例
- 通过调用系统摄像头拍照,拍视频
- ios 通过调用系统摄像头拍照,…
- android 调用 系统 相机 摄像机 拍照 拍视频
- IOS 调用摄像头拍照
- iOS摄像头拍照或者摄像的数据写入到文件
- Android 调用摄像头功能【拍照与视频】
- iOS拍照和录制视频 摄像头使用
- 调用系统摄像头拍照,获取原图
- IOS调取系统摄像头并拍照
- Android 使用系统摄像头拍相片与拍视频,并显示
- 用jmf调用摄像头视频拍照的例子
- 《OpenCV》Part2 OpenCV3.1.0调用摄像头显示视频并拍照
- android Camera摄像头-Surface view 预览拍照 并将拍的照片插入到系统图库
- 数据结构笔记--创建一个无向图
- 是tcp和udp只和套接字类型有关,和send,recv,connect无关,这些都是协议无关的函数
- Java混淆工具ProGuard的最简明使用方法及Warning: can’t find referenced class xxx的解决方法
- scala?ruby?python?学哪个
- android如何设置控件的样式
- ios 通过调用系统摄像头拍照,拍视频,然后写入文件
- CSS HACK 区别 IE6、IE7、IE8、Firefox兼容性
- 平凡程序员的悲哀
- 系统流程图简介
- Ubuntu12.04安装fcitx
- 清空easyui datagrid
- Stanford机器学习---第三讲. 逻辑回归和过拟合问题的解决 logistic Regression & Regularization
- STS(Eclipse)中配置hibernate连接Oracle数据库的方法详细描述
- 16进制字符串转换为10进制数字方法,负数的16进制需要BigInteger封装