Search code examples
javaandroidandroid-studioandroid-cameracamera-overlay

How can I create a virtual camera in Android to overlay on top of the real phone camera or create a new virtual camera source?


I'm working on an Android application where I want to capture the output of the real phone camera and overlay custom graphics on top of it. To achieve this, I need to create a virtual camera that will replace or overlay the output of the real camera. I'm unsure about the approach I should take to accomplish this.

Here's what I've tried so far:

I attempted to use the Android Camera API to capture the output of the real camera and draw graphics on top of it, but I couldn't get it to work as expected. I looked into the CameraX library, but couldn't find a direct method for creating a virtual camera. I'm a bit confused about what I should do next. Is there a way to create a virtual camera or manipulate the output of the real camera in Android? Any suggestions or guidance would be greatly appreciated.

My goal is to create a virtual camera source that appears as an option in other camera apps, allowing users to select it and see the output of the virtual camera with overlays or replacements.

Thank you.


Solution

  • A "virtual camera" is not how the Android API works. That's ok, you don't need to do that. If you want to overlay the camera, use a SurfaceView to display the camera image, then just draw on top of it. SurfaceViewHolder exposes a Canvas you can draw on with standard Android draw commands.