Skip to content

Commit

Permalink
fix: Fix wrong orientation enum being send to ImageCapture (#2683)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodgomesc committed Mar 25, 2024
1 parent ce23932 commit 4c00ffd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class CameraSession(private val context: Context, private val callback: Callback
}

photoOutput.flashMode = flash.toFlashMode()
photoOutput.targetRotation = outputOrientation.toDegrees()
photoOutput.targetRotation = outputOrientation.toSurfaceRotation()

val photoFile = photoOutput.takePicture(context, enableShutterSound, metadataProvider, callback, CameraQueues.cameraExecutor)
val isMirrored = photoFile.metadata.isReversedHorizontal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mrousavy.camera.types

import android.view.Surface

enum class Orientation(override val unionValue: String) : JSUnionValue {
PORTRAIT("portrait"),
LANDSCAPE_RIGHT("landscape-right"),
Expand All @@ -14,6 +16,14 @@ enum class Orientation(override val unionValue: String) : JSUnionValue {
LANDSCAPE_RIGHT -> 270
}

fun toSurfaceRotation(): Int =
when (this) {
PORTRAIT -> Surface.ROTATION_0
LANDSCAPE_LEFT -> Surface.ROTATION_90
PORTRAIT_UPSIDE_DOWN -> Surface.ROTATION_180
LANDSCAPE_RIGHT -> Surface.ROTATION_270
}

companion object : JSUnionValue.Companion<Orientation> {
override fun fromUnionValue(unionValue: String?): Orientation =
when (unionValue) {
Expand Down

0 comments on commit 4c00ffd

Please sign in to comment.