Skip to content

Commit 9209acb

Browse files
author
Dan Oprea
committed
Use CROP REGION for 4x (better quality)
1 parent 9227e90 commit 9209acb

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

app/src/main/java/com/dan/simplerawcamera/CameraActivity.kt

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,7 @@ class CameraActivity : AppCompatActivity() {
876876
mBinding.switch4X.isChecked = false
877877
mBinding.switch4X.setOnCheckedChangeListener { _, isChecked ->
878878
giveHapticFeedback(mBinding.switchSequences)
879-
val scale = if (isChecked) 4.0f else 1.0f
880-
mBinding.surfaceView.scaleX = scale
881-
mBinding.surfaceView.scaleY = scale
879+
setupCapturePreviewRequest()
882880
}
883881

884882
mOrientationEventListener = object: OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
@@ -1450,19 +1448,6 @@ class CameraActivity : AppCompatActivity() {
14501448
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true)
14511449
}
14521450

1453-
when( settings.takePhotoModes ) {
1454-
Settings.PHOTO_TYPE_DNG -> {
1455-
captureRequestBuilder.addTarget(mImageReaderDng.surface)
1456-
}
1457-
Settings.PHOTO_TYPE_JPEG -> {
1458-
captureRequestBuilder.addTarget(mImageReaderJpeg.surface)
1459-
}
1460-
else -> {
1461-
captureRequestBuilder.addTarget(mImageReaderDng.surface)
1462-
captureRequestBuilder.addTarget(mImageReaderJpeg.surface)
1463-
}
1464-
}
1465-
14661451
mLocation = if (settings.useLocation) {
14671452
mLocationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER)
14681453
} else {
@@ -1485,6 +1470,21 @@ class CameraActivity : AppCompatActivity() {
14851470
}
14861471
)
14871472

1473+
captureRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, Rect(0, 0, mCameraInfo.resolutionWidth, mCameraInfo.resolutionHeight))
1474+
1475+
when( settings.takePhotoModes ) {
1476+
Settings.PHOTO_TYPE_DNG -> {
1477+
captureRequestBuilder.addTarget(mImageReaderDng.surface)
1478+
}
1479+
Settings.PHOTO_TYPE_JPEG -> {
1480+
captureRequestBuilder.addTarget(mImageReaderJpeg.surface)
1481+
}
1482+
else -> {
1483+
captureRequestBuilder.addTarget(mImageReaderDng.surface)
1484+
captureRequestBuilder.addTarget(mImageReaderJpeg.surface)
1485+
}
1486+
}
1487+
14881488
mCaptureRequest = captureRequestBuilder.build()
14891489
} else {
14901490
mLocation = null
@@ -1512,6 +1512,17 @@ class CameraActivity : AppCompatActivity() {
15121512

15131513
if (photoMode) return
15141514

1515+
if (mBinding.switch4X.isChecked) {
1516+
val croppedWidth = mCameraInfo.resolutionWidth / 4
1517+
val croppedHeight = mCameraInfo.resolutionHeight / 4
1518+
val croppedLeft = (mCameraInfo.resolutionWidth - croppedWidth) / 2
1519+
val croppedTop = (mCameraInfo.resolutionHeight - croppedHeight) / 2
1520+
val croppedRect = Rect( croppedLeft, croppedTop, croppedLeft + croppedWidth - 1, croppedTop + croppedHeight - 1 )
1521+
captureRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, croppedRect)
1522+
} else {
1523+
captureRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, Rect(0, 0, mCameraInfo.resolutionWidth, mCameraInfo.resolutionHeight))
1524+
}
1525+
15151526
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, getFlashModeValue(true))
15161527
captureRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW)
15171528

0 commit comments

Comments
 (0)