-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
❓ Trying to taking photos in landscape mode #213
Comments
Hi! Thanks for the report, I'll start working on landscape mode soon, but it doesn't have very high priority since our app only supports portrait orientation. Related to #210 |
oh, ok man, thanks, you know some kind of workaround that i can do to this? |
You'd need to bind an orientation listener when you setup the camera and update the camera rotation accordingly. It'd look something like this (snippet taken from react-native-camera-kit): //Android
orientationListener = object : OrientationEventListener(context, SensorManager.SENSOR_DELAY_UI) {
override fun onOrientationChanged(orientation: Int) {
val imageCapture = imageCapture ?: return
var newOrientation: Int = imageCapture.targetRotation
if (orientation >= 315 || orientation < 45) {
newOrientation = Surface.ROTATION_0
} else if (orientation in 225..314) {
newOrientation = Surface.ROTATION_90
} else if (orientation in 135..224) {
newOrientation = Surface.ROTATION_180
} else if (orientation in 45..134) {
newOrientation = Surface.ROTATION_270
}
if (newOrientation != imageCapture.targetRotation) {
imageCapture.targetRotation = newOrientation
onOrientationChange(newOrientation)
}
}
} I had the same problem as you, I wanted to solve it, but unfortunately Vision Camera relies on coroutines and I'm not too familiar with them. FYI: In case you need to fix orientations (e.g. set the camera only in landscape) as well, you could use my fork of react-native-camera-kit: https://github.com/LupulescuAlexandru/react-native-camera-kit. |
This library is nearly perfect for us, especially considering none of the other popular libraries seem to support the iPhone triple camera setup. Orientation support has been the only sticking point for us so far, since 95% of our photos are taken in landscape. To get this working, I was able to patch diff --git a/node_modules/react-native-vision-camera/ios/CameraView+TakePhoto.swift b/node_modules/react-native-vision-camera/ios/CameraView+TakePhoto.swift
index be988bc..8c516ae 100644
--- a/node_modules/react-native-vision-camera/ios/CameraView+TakePhoto.swift
+++ b/node_modules/react-native-vision-camera/ios/CameraView+TakePhoto.swift
@@ -103,6 +103,20 @@ extension CameraView {
photoSettings.isAutoContentAwareDistortionCorrectionEnabled = enableAutoDistortionCorrection
}
+ // use actual device orientation
+ if let photoOutputConnection = photoOutput.connection(with: .video) {
+ switch UIDevice.current.orientation {
+ case .landscapeLeft:
+ photoOutputConnection.videoOrientation = .landscapeRight
+ case .landscapeRight:
+ photoOutputConnection.videoOrientation = .landscapeLeft
+ case .portraitUpsideDown:
+ photoOutputConnection.videoOrientation = .portraitUpsideDown
+ default:
+ photoOutputConnection.videoOrientation = .portrait
+ }
+ }
+
photoOutput.capturePhoto(with: photoSettings, delegate: PhotoCaptureDelegate(promise: promise))
// Assume that `takePhoto` is always called with the same parameters, so prepare the next call too. |
Implemented in #715! Hope this works for you :) If you appreciate the work I do in my free time, please consider sponsoring me on GitHub, it would mean a lot to me. 🖤 |
@mrousavy Thanks! As far as I can tell, this doesn't detect orientation though? In the native iOS camera app, the UI stays portrait, but the camera knows when you've rotated the device. Using this new prop, if we wanted to do the same, would we have to somehow track device orientation separately and pass that into the |
Exactly, you can override |
Hey - I'm tracking Orientation in this feature request/issue now: #1891 ✨ Make sure to upvote or sponsor to support this feature, and leave a comment if you have any additional thoughts/ideas. |
Hello, i'm trying to take photos in landscape but always the photo is on portrait mode, have a way to change this?
The text was updated successfully, but these errors were encountered: