mirror of
https://github.com/status-im/react-native-camera.git
synced 2025-02-24 09:48:17 +00:00
Support orientation option when taking picture on ios
This commit is contained in:
parent
d843de4eb6
commit
4ffedae792
@ -309,7 +309,13 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
|
||||
- (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
|
||||
{
|
||||
AVCaptureConnection *connection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
|
||||
[connection setVideoOrientation:[RNCameraUtils videoOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]]];
|
||||
int orientation;
|
||||
if ([options[@"orientation"] integerValue]) {
|
||||
orientation = [options[@"orientation"] integerValue];
|
||||
} else {
|
||||
orientation = [RNCameraUtils videoOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]];
|
||||
}
|
||||
[connection setVideoOrientation:orientation];
|
||||
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:connection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
|
||||
if (imageSampleBuffer && !error) {
|
||||
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
|
||||
|
@ -18,6 +18,14 @@ typedef NS_ENUM(NSInteger, RNCameraFlashMode) {
|
||||
RNCameraFlashModeAuto = AVCaptureFlashModeAuto
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, RNCameraOrientation) {
|
||||
RNCameraOrientationAuto = 0,
|
||||
RNCameraOrientationLandscapeLeft = AVCaptureVideoOrientationLandscapeLeft,
|
||||
RNCameraOrientationLandscapeRight = AVCaptureVideoOrientationLandscapeRight,
|
||||
RNCameraOrientationPortrait = AVCaptureVideoOrientationPortrait,
|
||||
RNCameraOrientationPortraitUpsideDown = AVCaptureVideoOrientationPortraitUpsideDown
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, RNCameraAutoFocus) {
|
||||
RNCameraAutoFocusOff = AVCaptureFocusModeLocked,
|
||||
RNCameraAutoFocusOn = AVCaptureFocusModeContinuousAutoFocus,
|
||||
|
@ -56,6 +56,13 @@ RCT_EXPORT_VIEW_PROPERTY(onFacesDetected, RCTDirectEventBlock);
|
||||
@"4:3": @(RNCameraVideo4x3),
|
||||
@"288p": @(RNCameraVideo288p),
|
||||
},
|
||||
@"Orientation": @{
|
||||
@"auto": @(RNCameraOrientationAuto),
|
||||
@"landscapeLeft": @(RNCameraOrientationLandscapeLeft),
|
||||
@"landscapeRight": @(RNCameraOrientationLandscapeRight),
|
||||
@"portrait": @(RNCameraOrientationPortrait),
|
||||
@"portraitUpsideDown": @(RNCameraOrientationPortraitUpsideDown)
|
||||
},
|
||||
@"VideoCodec": [[self class] validCodecTypes],
|
||||
@"BarCodeType" : [[self class] validBarCodeTypes],
|
||||
@"FaceDetection" : [[self class] faceDetectorConstants]
|
||||
|
@ -30,8 +30,11 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
});
|
||||
|
||||
type Orientation = "auto"|"landscapeLeft"|"landscapeRight"|"portrait"|"portraitUpsideDown";
|
||||
|
||||
type PictureOptions = {
|
||||
quality?: number,
|
||||
orientation?: Orientation,
|
||||
base64?: boolean,
|
||||
mirrorImage?: boolean,
|
||||
exif?: boolean,
|
||||
@ -247,6 +250,9 @@ export default class Camera extends React.Component<PropsType, StateType> {
|
||||
if (!options.quality) {
|
||||
options.quality = 1;
|
||||
}
|
||||
if (options.orientation) {
|
||||
options.orientation = CameraManager.Orientation[options.orientation];
|
||||
}
|
||||
return await CameraManager.takePicture(options, this._cameraHandle);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user