How to add photo to imagecapture?

128 views
Skip to first unread message
Assigned to charco...@google.com by wuj...@google.com

Jakub Bober

unread,
Jun 6, 2022, 4:39:44 AM6/6/22
to Android CameraX Discussion Group
 I have tis fun to take photo


private fun takePhoto(): Boolean {
  mediaPlayer.start()

// Get a stable reference of the modifiable image capture use case
        val imageCapture = imageCapture ?: return false
        imageCapture.

        val nameFile = getFormatFile02(getString(R.string.app_name).lowercase())

        val contentValues = getContentValuesFileName(nameFile, actualCameraDimensionSelect.width,
                actualCameraDimensionSelect.height)

        //var tezt = imageCapture.

        // Create the output file option to store the captured image in MediaStore
        val outputFileOptions = ImageCapture.OutputFileOptions
                .Builder(contentResolver, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
                .build()

        // Set up image capture listener, which is triggered after photo has been taken
        imageCapture.takePicture(outputFileOptions,
                ContextCompat.getMainExecutor(this), object : ImageCapture.OnImageSavedCallback {
                        override fun onError(exc: ImageCaptureException) {
                            showSnackBar(resources.getString(R.string.photo_capture_failed), fontTextSize, Snackbar.LENGTH_LONG, numberRow = 2)
                        }

                        override fun onImageSaved(output: ImageCapture.OutputFileResults) {
                            showSnackBar(nameFile, fontTextSize, Snackbar.LENGTH_SHORT, numberRow = 7)
                    }
                })

        return true
    }


How to add tezt to the picture object ImageCapture?

Thanks for answer
Jakub   

Charcoal Chen

unread,
Jun 8, 2022, 6:10:43 AM6/8/22
to Android CameraX Discussion Group, bobe...@gmail.com
Hi,

It looks like your code is implemented by referring to Getting Stared with CameraX - Implement ImageCapture use case. I guess your question is about how to bind the ImageCapture use case to a lifecycle owner (Activity, Fragment, etc.). Please also refer to the "3. Finally, update the call to bindToLifecycle() in the try block to include the new use case:" section in Getting Stared with CameraX - Implement ImageCapture use case. You will need to get a ProcessCameraProvider instance and then use ProcessCameraProvider#bindToLifecycle() API to bind the ImageCapture use case to a lifecycle owner.

Maybe you can also try to download/compile the  CameraXBasic sampe app and refer to the CameraFragment.kt class. 

If I misunderstand your question, please let me know. Thanks.
Reply all
Reply to author
Forward
0 new messages