Omri Nachmani
unread,Apr 25, 2021, 8:48:27 AM4/25/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android CameraX Discussion Group, Omri Nachmani, Scott Nien, Android CameraX Discussion Group, lbypa...@gmail.com
So i have managed to set up camerax in a fragment and have an imageview waiting for the image in another fragment. My current struggle is to send the image proxy to the other fragment. I am using NavDirections that uses Bundle to pass Safe Args from one fragment to another. In the design tab I can add arguments but the type must be declared and I don't know how to ensure it can interpret the image type. Is there a better way?
Code below:
CameraXFragment: takePhoto function
private fun takePhoto() {
// Get a stable reference of the modifiable image capture use case
val imageCapture = imageCapture ?: return
// Setup image capture listener which is triggered after photo has
// been taken
imageCapture.takePicture(ContextCompat.getMainExecutor(safeContext), object : ImageCapture.OnImageCapturedCallback() {
override fun onError(exc: ImageCaptureException) {
Log.e(TAG, "Photo capture failed: ${exc.message}", exc)
}
@SuppressLint("UnsafeExperimentalUsageError")
override fun onCaptureSuccess(image: ImageProxy) {
val faceImage = image.image
findNavController().navigate(CameraXViewDirections.actionCameraXViewToReviewImageFragment(faceImage))
super.onCaptureSuccess(image)
}
})
}
ReviewImageFragment
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val binding = DataBindingUtil.inflate<FragmentReviewImageBinding>(
inflater, R.layout.fragment_review_image, container, false)
// Inflate the layout for this fragment
val args = reviewImageFragmentArgs.fromBundle(requireArguments())
binding.imageView.setImageResource(args.faceImage)
return binding.root
}
navigation.xml:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="
http://schemas.android.com/apk/res/android"
xmlns:app="
http://schemas.android.com/apk/res-auto"
xmlns:tools="
http://schemas.android.com/tools"
android:id="@+id/navigation"
app:startDestination="@id/cameraXViewFragment">
<fragment
android:id="@+id/cameraXViewFragment"
android:name="com.example.faceanalysis.CameraXView"
android:label="CameraXView" >
<action
android:id="@+id/action_cameraXView_to_reviewImageFragment"
app:destination="@id/reviewImageFragment" />
</fragment>
<fragment
android:id="@+id/reviewImageFragment"
android:name="com.example.faceanalysis.reviewImageFragment"
android:label="fragment_review_image"
tools:layout="@layout/fragment_review_image" >
<argument android:name="faceImage" />
</fragment>
</navigation>