From 64204503fe4c081c8308a2e78eed76a974da489b Mon Sep 17 00:00:00 2001 From: MRSa Date: Thu, 25 Nov 2021 23:59:52 +0900 Subject: [PATCH] =?utf8?q?cameraX=E3=81=AE=E5=B0=91=E3=81=97=E6=9B=B4?= =?utf8?q?=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 8 +- .../vendor/camerax/operation/CameraControl.kt | 128 +++++++++++++-------- build.gradle | 2 +- 3 files changed, 86 insertions(+), 52 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e1d9677..f187377 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,17 +34,17 @@ dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.exifinterface:exifinterface:1.3.3' implementation "androidx.core:core-ktx:1.7.0" - implementation 'androidx.appcompat:appcompat:1.3.1' - implementation 'androidx.constraintlayout:constraintlayout:2.1.1' + implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'com.google.android.material:material:1.4.0' - def camerax_version = "1.1.0-alpha10" + def camerax_version = "1.1.0-alpha11" implementation "androidx.camera:camera-core:$camerax_version" implementation "androidx.camera:camera-camera2:$camerax_version" implementation "androidx.camera:camera-lifecycle:$camerax_version" - def camerax_view_version = "1.0.0-alpha30" + def camerax_view_version = "1.0.0-alpha31" implementation "androidx.camera:camera-extensions:$camerax_view_version" implementation "androidx.camera:camera-view:$camerax_view_version" diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/camerax/operation/CameraControl.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/camerax/operation/CameraControl.kt index 1393b8b..a82758d 100644 --- a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/camerax/operation/CameraControl.kt +++ b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/camerax/operation/CameraControl.kt @@ -159,55 +159,10 @@ class CameraControl(private val activity : AppCompatActivity, private val prefer val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get() val imageCapture = fileControl.prepare() val option1 = preference.getCameraOption1() // プレビューサイズを設定する - val previewSize = if (option1.isNotBlank()) { - when (option1) { - "_8K" -> Size(4320, 7680) - "_6K" -> Size(3384, 6016) - "_4K" -> Size(4096, 2160) - "_WQHD" -> Size(2560, 1440) - "_2K" -> Size(2048, 1080) - "_FHD" -> Size(1920, 1080) - "_SXGA" -> Size(1280, 1024) // SXGA : 1600x1200 @ Pixel3a - "_XGA" -> Size(1024, 768) // XGA : 1600x1200 @ Pixel3a - "_SVGA" -> Size(800, 600) // SVGA : 1280x960 @ Pixel3a - "_VGA" -> Size(640, 480) // SVGA : 1280x960 @ Pixel3a - "8K" -> Size(7680, 4320) - "6K" -> Size(6016, 3384) - "4K" -> Size(2160, 4096) - "WQHD" -> Size(1440, 2560) - "2K" -> Size(1080, 2048) - "FHD" -> Size(1080, 1920) - "SXGA" -> Size(1024, 1280) - "XGA" -> Size(768, 1024) - "SVGA" -> Size(600, 800) - "VGA" -> Size(480, 640) - else -> Size(480, 640) // VGA : 1024x768 @ Pixel3a - } - } - else - { - Size(640, 480) - } + val option2 = preference.getCameraOption2() // テスト用オプション... try { - val imageAnalyzer = if (option1.isNotBlank()) { - ImageAnalysis.Builder() - .setTargetResolution(previewSize) - .setTargetRotation(getImageRotation()) - .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) - .build() - .also { - it.setAnalyzer(cameraExecutor, liveViewListener) - } - } else { - ImageAnalysis.Builder() - .setTargetRotation(getImageRotation()) - .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) - .build() - .also { - it.setAnalyzer(cameraExecutor, liveViewListener) - } - } + val imageAnalyzer = getImageAnalysis(option1, option2) cameraProvider.unbindAll() cameraXCamera = cameraProvider.bindToLifecycle(activity, cameraSelector, imageCapture, imageAnalyzer) cameraXCameraControl.setCameraControl(cameraXCamera) @@ -223,6 +178,85 @@ class CameraControl(private val activity : AppCompatActivity, private val prefer }, ContextCompat.getMainExecutor(activity)) } + private fun getImageAnalysis(option1 : String, option2 : String) : ImageAnalysis + { + Log.v(TAG, " getImageAnalysis(option1 = '$option1', option2 = '$option2') ") + val previewSize = if (option1.isNotBlank()) { + when (option1) { + "_8K" -> Size(4320, 7680) + "_6K" -> Size(3384, 6016) + "_4K" -> Size(4096, 2160) + "_WQHD" -> Size(2560, 1440) + "_2K" -> Size(2048, 1080) + "_FHD" -> Size(1920, 1080) + "_SXGA" -> Size(1280, 1024) // SXGA : 1600x1200 @ Pixel3a + "_XGA" -> Size(1024, 768) // XGA : 1600x1200 @ Pixel3a + "_SVGA" -> Size(800, 600) // SVGA : 1280x960 @ Pixel3a + "_VGA" -> Size(640, 480) // SVGA : 1280x960 @ Pixel3a + "8K" -> Size(7680, 4320) + "6K" -> Size(6016, 3384) + "4K" -> Size(2160, 4096) + "WQHD" -> Size(1440, 2560) + "2K" -> Size(1080, 2048) + "FHD" -> Size(1080, 1920) + "SXGA" -> Size(1024, 1280) + "XGA" -> Size(768, 1024) + "SVGA" -> Size(600, 800) + "VGA" -> Size(480, 640) + else -> Size(480, 640) // VGA : 1024x768 @ Pixel3a + } + } + else + { + Size(640, 480) + } + //val useImageFormatOption = false + return (//if (!useImageFormatOption) { + if (option1.isNotBlank()) { + ImageAnalysis.Builder() + .setTargetResolution(previewSize) + .setTargetRotation(getImageRotation()) + .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) + .build() + .also { + it.setAnalyzer(cameraExecutor, liveViewListener) + } + } else { + ImageAnalysis.Builder() + .setTargetRotation(getImageRotation()) + .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) + .build() + .also { + it.setAnalyzer(cameraExecutor, liveViewListener) + } + } + //} + /*else + { + if (option1.isNotBlank()) { + ImageAnalysis.Builder() + .setTargetResolution(previewSize) + .setTargetRotation(getImageRotation()) + .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) + .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888) + .build() + .also { + it.setAnalyzer(cameraExecutor, liveViewListener) + } + } else { + ImageAnalysis.Builder() + .setTargetRotation(getImageRotation()) + .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) + .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888) + .build() + .also { + it.setAnalyzer(cameraExecutor, liveViewListener) + } + } + }*/ + ) + } + @SuppressLint("UnsafeOptInUsageError") private fun setCaptureRequestOptions(cameraControl : androidx.camera.core.CameraControl) { diff --git a/build.gradle b/build.gradle index 5752b08..cfe8c91 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.5.31" + ext.kotlin_version = "1.6.0" repositories { google() mavenCentral() -- 2.11.0