diff --git a/Example/Example.js b/Example/Example.js index 41691ea..e86185b 100644 --- a/Example/Example.js +++ b/Example/Example.js @@ -13,10 +13,10 @@ const styles = StyleSheet.create({ flex: 1, }, preview: { + flex: 1, alignSelf: "stretch", justifyContent: 'flex-end', - alignItems: 'center', - height: 200 + alignItems: 'center' }, overlay: { position: 'absolute', @@ -187,6 +187,7 @@ export default class Example extends React.Component { onZoomChanged={() => {}} defaultTouchToFocus mirrorImage={false} + cropToPreview={false} /> UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeRight UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance diff --git a/ios/RCTCameraManager.m b/ios/RCTCameraManager.m index d2e09c3..5a95089 100644 --- a/ios/RCTCameraManager.m +++ b/ios/RCTCameraManager.m @@ -627,15 +627,6 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej // create cgimage CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, NULL); - - // Crop it (if capture quality is set to preview) - if (self.cropToPreview) { - CGSize viewportSize = CGSizeMake(self.previewLayer.frame.size.width, self.previewLayer.frame.size.height); - CGRect captureRect = CGRectMake(0, 0, CGImageGetWidth(cgImage), CGImageGetHeight(cgImage)); - CGRect croppedSize = AVMakeRectWithAspectRatioInsideRect(viewportSize, captureRect); - - cgImage = CGImageCreateWithImageInRect(cgImage, croppedSize); - } // Rotate it CGImageRef rotatedCGImage; @@ -665,6 +656,22 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej } else { rotatedCGImage = cgImage; } + + // Crop it + if (self.cropToPreview) { + CGSize viewportSize; + + if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) + { + viewportSize = CGSizeMake(self.previewLayer.frame.size.height, self.previewLayer.frame.size.width); + } else { + viewportSize = CGSizeMake(self.previewLayer.frame.size.width, self.previewLayer.frame.size.height); + } + + CGRect captureRect = CGRectMake(0, 0, CGImageGetWidth(rotatedCGImage), CGImageGetHeight(rotatedCGImage)); + CGRect croppedSize = AVMakeRectWithAspectRatioInsideRect(viewportSize, captureRect); + rotatedCGImage = CGImageCreateWithImageInRect(rotatedCGImage, croppedSize); + } // Erase stupid TIFF stuff [imageMetadata removeObjectForKey:(NSString *)kCGImagePropertyTIFFDictionary];