프리뷰
fun initAndroidXCamera() {
.
.
val previewConfig = PreviewConfig.Builder().apply{
setLensFacing(CameraX.LensFacing.FRONT)
setTargetAspectRatio(Rational(1,1))
setTargetResolution(Size(480,640))
}.build()
val preview = Preview( previewConfig )
preview.setOnPreviewOutputUpdateListener {
Log.d(TAG, "onPreviewOutputUpdate")
val parent = binding.viewFinder.parent as ViewGroup
parent.removeView(binding.viewFinder)
parent.addView(binding.viewFinder, 0)
binding.viewFinder.surfaceTexture = it.surfaceTexture
updateTransform()
}
.
.
}
private fun updateTransform() {
val matrix = Matrix()
val centerX = binding.viewFinder.width / 2f
val centerY = binding.viewFinder.height / 2f
val rotationDegrees = when( binding.viewFinder.display.rotation ) {
Surface.ROTATION_0 -> 0
Surface.ROTATION_90 -> 90
Surface.ROTATION_180 -> 180
Surface.ROTATION_270 -> 270
else -> return
}
matrix.postRotate( -rotationDegrees.toFloat(), centerX, centerY)
binding.viewFinder.setTransform(matrix)
}
스냅샷
fun initAndroidXCamera(){
.
.
val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
setLensFacing(CameraX.LensFacing.FRONT)
setTargetAspectRatio(Rational(1,1))
setTargetResolution(Size(480,640))
setCaptureMode(ImageCapture.CaptureMode.MIN_LATENCY)
}.build()
val imageCapture = ImageCapture( imageCaptureConfig )
imageCapture.takePicture ( object:ImageCapture.OnImageCapturedListener() {
override fun onCaptureSuccess(image: ImageProxy?, rotationDegrees: Int) {
super.onCaptureSuccess(image, rotationDegrees)
}
override fun onError(useCaseError: ImageCapture.UseCaseError?, message: String?, cause: Throwable?) {
super.onError(useCaseError, message, cause)
}
})
.
.
}
Analyzer
fun initAndroidXCamera() {
.
.
// analyzer
val analyzerConfig = ImageAnalysisConfig.Builder().apply {
val thread = HandlerThread("ImageAnalyzer").apply {
start()
}
setCallbackHandler(Handler( thread.looper ))
setLensFacing(CameraX.LensFacing.FRONT)
setTargetAspectRatio(Rational(1,1))
setTargetResolution(Size(480,640))
setImageReaderMode( ImageAnalysis.ImageReaderMode.ACQUIRE_NEXT_IMAGE )
}.build()
val analyzer = ImageAnalysis( analyzerConfig )
analyzer.analyzer = ImageAnalyzer(this)
.
.
}
class ImageAnalyzer(activity:ExternalCaptureActivity) : ImageAnalysis.Analyzer {
private val activity:ExternalCaptureActivity = activity
override fun analyze(imageProxy: ImageProxy?, rotationDegrees: Int) {
Log.d(activity.TAG, "analyze");
val image = imageProxy?.image
if( image != null ) {
// 획득한 image에 대한 처리를 추가
}
}
}
'프로그래밍 > Android' 카테고리의 다른 글
안드로이드 ndk 테스트 코드 (0) | 2020.02.20 |
---|---|
[Android] gson , 복합적인 요소의 파싱 (0) | 2019.09.23 |
[Android] gradle android 빌드 구성 (0) | 2019.09.17 |
[Android] ConstraintSet (0) | 2019.08.22 |
Gradle Kotlin, AndroidX 설정 (0) | 2019.08.17 |
[Android] Retrofit (0) | 2019.04.11 |
[Android] Data Binding Library (0) | 2019.03.31 |
String 리소스에 html 태그 넣기 (0) | 2014.04.29 |
파일 변경 이벤트 (0) | 2014.04.01 |
[안드로이드TV] 개발 전 확인사항 (0) | 2014.02.17 |