0LLiena
0LLiena

Reputation: 135

"Mirror" android inside camera in screen view

I have the following java method:

private Camera openFrontFacingCameraGingerbread() {
        int cameraCount = 0;
        Camera cam = null;
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        cameraCount = Camera.getNumberOfCameras();
        for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
            Camera.getCameraInfo(camIdx, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                try {
                    cam = Camera.open(camIdx);
                } catch (RuntimeException e) {
                    Toast.makeText(debug, "failed", Toast.LENGTH_LONG).show();
                }
            }
        }

and what I'm looking forward to do is mirror the camera in the screen. This is, as soon as I open the app I would like the user to see himself but I'm not being able to accomplish this.

Here is the onCreate method of the same class:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        openFrontFacingCameraGingerbread();
    }

Can someone help me on this one? Thank you very much

Upvotes: 0

Views: 272

Answers (1)

matiash
matiash

Reputation: 55370

You need to include a SurfaceView in your layout, and use setPreviewDisplay() and startPreview(). This will draw the camera's input in your Activity.

You should check the developer guides, and also take a look at Android - Camera Preview

Upvotes: 1

Related Questions