iOS - 录像、拍照

1、导入框架#import ->UIImagePickerController

2、先区分选择摄像头、相册sourceType

(1)UIImagePickerControllerSourceTypePhotoLibrary摄像头

(2)UIImagePickerControllerSourceTypeCamera相册

(3)UIImagePickerControllerSourceTypeSavedPhotosAlbum相册

3、再区分录像与拍照cameraCaptureMode:

(0)设置录像->要先选择媒体的类型默认拍照不崩溃因为默认设置媒体类型是kUTTypeImage※※※※※※不然会崩溃

(1)录像:UIImagePickerControllerCameraCaptureModeVideo

(2)拍照:UIImagePickerControllerCameraCaptureModePhoto

4、区分前后摄像头cameraDevice

(1)UIImagePickerControllerCameraDeviceRear前摄像头

(2)UIImagePickerControllerCameraDeviceFront后摄像头

5、选择媒体类型mediaTypes

(1)选择媒体类型默认kUTTypeImage

(2)kUTTypeImage包含在框架->#import

(3)需要的内容不是OC里面的字符串类型需要强制转换

(4)录制视频->类型要选择kUTTypeMovie它里面包含了audio和vidio

6、设置是否显示控制控件showsCameraControls

7、设置拍照takePicture

8、录像startVideoCapture、stopVideoCapture

9、设置视频清晰度videoQu

(1)UIImagePickerControllerQualityTypeHigh

(2)UIImagePickerControllerQualityTypeMedium

(3)UIImagePickerControllerQualityTypeLow

(4)UIImagePickerControllerQualityType640x480

(5)UIImagePickerControllerQualityTypeIFrame1280x720

(6)UIImagePickerControllerQualityTypeIFrame960x540

10、设置视频最大的录像时间videoMaximumDuration

11、设置闪光cameraFlashMode

(1)UIImagePickerControllerCameraFlashModeOff关闭

(2)UIImagePickerControllerCameraFlashModeAuto自动-默认

(3)UIImagePickerControllerCameraFlashModeOn开启

12、设置调用摄像头视频页面的覆盖视图cameraOverlayView

13、设置拍照页面的形态cameraViewTransform

14、代理delegate需要导入两个代理

方法:

- (void)imagePickerController:(UIImagePickerController *)picker

didFinishPickingMediaWithInfo:(NSDictionary *)info;采集完成之后调用、不区分摄像拍照

- (void)imagePickerControllerDidCancel:(UIImagePickerController

*)picker;采集取消的时候调用

15、(1)把图片保存到相册

UIImageWriteToSavedPhotosAlbum(finishImage,

self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

(2)保存成功的回调方法

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error

contextInfo:(void *)contextInfo{

NSLog(@"图片保存成功");

}

16、(1)保存视频到相册

NSString *path = (NSString *)[info[UIImagePickerControllerMediaURL] path];

UISaveVideoAtPathToSavedPhotosAlbum(path,

self, @selector(video:didFinishSavingWithError:contextInfo:), nil);

(2)视频保存到相册之后调用

- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error

contextInfo:(void *)contextInfo{

}

17、(1)JPEG格式图片转换成NSData

NSData *imageData = UIImageJPEGRepresentation(finishImage, 0.1);

(2)PNG格式图片转换成NSData

NSData *imageData1 = UIImagePNGRepresentation(finishImage);

你可能感兴趣的:(iOS - 录像、拍照)