Skip to content

Instantly share code, notes, and snippets.

@jeremybarbet
Last active August 14, 2021 18:33
Show Gist options
  • Select an option

  • Save jeremybarbet/c89698df5ddd8f312de04aed4f2dc555 to your computer and use it in GitHub Desktop.

Select an option

Save jeremybarbet/c89698df5ddd8f312de04aed4f2dc555 to your computer and use it in GitHub Desktop.
diff --git a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt
index f6dc227..f2446f0 100644
--- a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt
+++ b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt
@@ -356,9 +356,11 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
// User has selected a custom format={}. Use that
val format = DeviceFormat(format!!)
Log.i(TAG, "Using custom format - photo: ${format.photoSize}, video: ${format.videoSize} @ $fps FPS")
- previewBuilder.setTargetResolution(format.videoSize)
- imageCaptureBuilder.setTargetResolution(format.photoSize)
- videoCaptureBuilder.setTargetResolution(format.videoSize)
+ val photoAspectRatio = aspectRatio(format.photoHeight, format.photoWidth)
+ val videoAspectRatio = aspectRatio(format.videoHeight, format.videoWidth)
+ previewBuilder.setTargetAspectRatio(videoAspectRatio)
+ imageCaptureBuilder.setTargetAspectRatio(photoAspectRatio)
+ videoCaptureBuilder.setTargetAspectRatio(videoAspectRatio)
fps?.let { fps ->
if (format.frameRateRanges.any { it.contains(fps) }) {
diff --git a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/utils/DeviceFormat.kt b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/utils/DeviceFormat.kt
index 3364d8c..2fe8e1c 100644
--- a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/utils/DeviceFormat.kt
+++ b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/utils/DeviceFormat.kt
@@ -6,8 +6,14 @@ import com.facebook.react.bridge.ReadableMap
class DeviceFormat(map: ReadableMap) {
val frameRateRanges: List<Range<Int>>
+
val photoSize: Size
+ val photoWidth: Int
+ val photoHeight: Int
+
val videoSize: Size
+ val videoWidth: Int
+ val videoHeight: Int
init {
frameRateRanges = map.getArray("frameRateRanges")!!.toArrayList().map { range ->
@@ -16,8 +22,14 @@ class DeviceFormat(map: ReadableMap) {
else
throw IllegalArgumentException("DeviceFormat: frameRateRanges contained a Range that was not of type HashMap<*,*>! Actual Type: ${range?.javaClass?.name}")
}
+
photoSize = Size(map.getInt("photoWidth"), map.getInt("photoHeight"))
+ photoWidth = map.getInt("photoWidth")
+ photoHeight = map.getInt("photoHeight")
+
videoSize = Size(map.getInt("videoWidth"), map.getInt("videoHeight"))
+ videoWidth = map.getInt("videoWidth")
+ videoHeight = map.getInt("videoHeight")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment