-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Take Orientation into account for
PreviewView
(#2565)
* fix: Take Orientation into account for `PreviewView` * Log * Take aspect ratio into account * Reorganize code a bit * Set LANDSCAPE_LEFT as default * chore: Format
- Loading branch information
Showing
6 changed files
with
87 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
...roid/src/main/java/com/mrousavy/camera/extensions/CameraCharacteristics+getPreviewSize.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
package/android/src/main/java/com/mrousavy/camera/extensions/Point+rotatedBy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mrousavy.camera.extensions | ||
|
||
import android.graphics.Point | ||
import android.graphics.PointF | ||
import android.util.Log | ||
import android.util.Size | ||
import com.mrousavy.camera.types.Orientation | ||
|
||
fun Point.rotatedBy(fromSize: Size, toSize: Size, fromOrientation: Orientation, toOrientation: Orientation): Point { | ||
val differenceDegrees = (fromOrientation.toDegrees() + toOrientation.toDegrees()) % 360 | ||
val difference = Orientation.fromRotationDegrees(differenceDegrees) | ||
val normalizedPoint = PointF(this.x / fromSize.width.toFloat(), this.y / fromSize.height.toFloat()) | ||
|
||
val rotatedNormalizedPoint = when (difference) { | ||
Orientation.PORTRAIT -> normalizedPoint | ||
Orientation.PORTRAIT_UPSIDE_DOWN -> PointF(1 - normalizedPoint.x, 1 - normalizedPoint.y) | ||
Orientation.LANDSCAPE_LEFT -> PointF(normalizedPoint.y, 1 - normalizedPoint.x) | ||
Orientation.LANDSCAPE_RIGHT -> PointF(1 - normalizedPoint.y, normalizedPoint.x) | ||
} | ||
|
||
val rotatedX = rotatedNormalizedPoint.x * toSize.width | ||
val rotatedY = rotatedNormalizedPoint.y * toSize.height | ||
Log.i("ROTATE", "$this -> $normalizedPoint -> $difference -> $rotatedX, $rotatedY") | ||
return Point(rotatedX.toInt(), rotatedY.toInt()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters