Fix image orientation, reduce sensitivity, fix overlay clipping
Image orientation: - Actually rotate captured bitmap using ImageProxy.rotationDegrees - Save with EXIF ORIENTATION_NORMAL (bitmap already correctly oriented) - Handle front camera mirroring Gesture sensitivity (halved again): - Position drag: 0.15x (was 0.3x) - Rotation: 0.2x (was 0.4x) - Size pinch: 0.25x (was 0.5x) - Zoom pinch: 0.4x (was 0.6x) Overlay drawing: - Use screen diagonal to calculate extended geometry - Draw lines and rectangles that extend beyond screen bounds - Prevents clipping when tilt-shift effect is rotated Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
3bbf4f9d14
commit
e3e05af0b8
2 changed files with 71 additions and 31 deletions
|
|
@ -51,8 +51,11 @@ class ImageCaptureHandler(
|
|||
object : ImageCapture.OnImageCapturedCallback() {
|
||||
override fun onCaptureSuccess(imageProxy: ImageProxy) {
|
||||
try {
|
||||
// Get rotation from ImageProxy (sensor orientation)
|
||||
val imageRotation = imageProxy.imageInfo.rotationDegrees
|
||||
|
||||
// Convert ImageProxy to Bitmap
|
||||
val bitmap = imageProxyToBitmap(imageProxy)
|
||||
var bitmap = imageProxyToBitmap(imageProxy)
|
||||
imageProxy.close()
|
||||
|
||||
if (bitmap == null) {
|
||||
|
|
@ -60,21 +63,19 @@ class ImageCaptureHandler(
|
|||
return
|
||||
}
|
||||
|
||||
// Apply tilt-shift effect to captured image
|
||||
// Rotate bitmap to correct orientation
|
||||
// Camera sensor is landscape, we need to rotate for portrait
|
||||
bitmap = rotateBitmap(bitmap, imageRotation, isFrontCamera)
|
||||
|
||||
// Apply tilt-shift effect to the correctly oriented image
|
||||
val processedBitmap = applyTiltShiftEffect(bitmap, blurParams)
|
||||
bitmap.recycle()
|
||||
|
||||
// Determine EXIF orientation
|
||||
val rotationDegrees = OrientationDetector.rotationToDegrees(deviceRotation)
|
||||
val exifOrientation = OrientationDetector.degreesToExifOrientation(
|
||||
rotationDegrees, isFrontCamera
|
||||
)
|
||||
|
||||
// Save with EXIF data
|
||||
// Save with EXIF orientation as NORMAL (bitmap is already rotated)
|
||||
kotlinx.coroutines.runBlocking {
|
||||
val result = photoSaver.saveBitmap(
|
||||
processedBitmap,
|
||||
exifOrientation,
|
||||
ExifInterface.ORIENTATION_NORMAL,
|
||||
location
|
||||
)
|
||||
processedBitmap.recycle()
|
||||
|
|
@ -94,6 +95,37 @@ class ImageCaptureHandler(
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a bitmap to the correct orientation.
|
||||
*/
|
||||
private fun rotateBitmap(bitmap: Bitmap, rotationDegrees: Int, isFrontCamera: Boolean): Bitmap {
|
||||
if (rotationDegrees == 0 && !isFrontCamera) {
|
||||
return bitmap
|
||||
}
|
||||
|
||||
val matrix = Matrix()
|
||||
|
||||
// Apply rotation
|
||||
if (rotationDegrees != 0) {
|
||||
matrix.postRotate(rotationDegrees.toFloat())
|
||||
}
|
||||
|
||||
// Mirror for front camera
|
||||
if (isFrontCamera) {
|
||||
matrix.postScale(-1f, 1f)
|
||||
}
|
||||
|
||||
val rotated = Bitmap.createBitmap(
|
||||
bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true
|
||||
)
|
||||
|
||||
if (rotated != bitmap) {
|
||||
bitmap.recycle()
|
||||
}
|
||||
|
||||
return rotated
|
||||
}
|
||||
|
||||
private fun imageProxyToBitmap(imageProxy: ImageProxy): Bitmap? {
|
||||
val buffer = imageProxy.planes[0].buffer
|
||||
val bytes = ByteArray(buffer.remaining())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue