Skip to content

Commit

Permalink
Aperture: Fix front camera intent preview mirroring
Browse files Browse the repository at this point in the history
With image capture intents, properly mirror the preview image for a
front-facing camera photo when the "Mirror front camera" feature is on,
as is the default. Otherwise, in addition to not being mirrored like
the live preview, the image preview may appear to be upside down.

Issue: calyxos#2642
Change-Id: I49b6256750ac821c6eefdd28ed7a4c2ec1c519c9
  • Loading branch information
t-m-w authored and luca020400 committed Aug 21, 2024
1 parent 5f6aa26 commit a7f50c1
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.Context
import android.graphics.BitmapFactory
import android.net.Uri
import android.util.AttributeSet
import android.util.Log
import android.widget.ImageButton
import android.widget.ImageView
import androidx.camera.camera2.interop.ExperimentalCamera2Interop
Expand Down Expand Up @@ -116,15 +117,22 @@ class CapturePreviewLayout(context: Context, attrs: AttributeSet?) : ConstraintL
MediaType.PHOTO -> {
if (uri != null) {
imageView.rotation = 0f
imageView.scaleX = 1f
imageView.setImageURI(uri)
} else {
val inputStream = photoInputStream!!
val transform = ExifUtils.getTransform(inputStream)
inputStream.mark(Int.MAX_VALUE)
val bitmap = BitmapFactory.decodeStream(inputStream)
inputStream.reset()
Log.d(LOG_TAG, "Preview transform=$transform screenRotation=$screenRotation")
imageView.rotation =
transform.rotation.offset.toFloat() - screenRotation.offset
imageView.scaleX = if (transform.mirror) {
-1f
} else {
1f
}
imageView.setImageBitmap(bitmap)
}
}
Expand Down Expand Up @@ -161,4 +169,8 @@ class CapturePreviewLayout(context: Context, attrs: AttributeSet?) : ConstraintL
cancelButton.smoothRotate(compensationValue)
confirmButton.smoothRotate(compensationValue)
}

companion object {
private const val LOG_TAG = "Aperture"
}
}

0 comments on commit a7f50c1

Please sign in to comment.