Ask Your Question
0

How to add a button to switch between cameras

asked 2013-05-21 10:36:16 -0600

sp_mic88 gravatar image

How can I add a button to camera-control opencv4android example? I have simply added in the main.xml file:

<button android:id="@+id/imgShoot" android:text="Capture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right"/> and in OnCreate function, in MainActivity.java, after setContentView:

final Button button = (Button) findViewById(R.id.button_id); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click } }); but it doesn't work. This button should be able to switch between front and back camera, in my device.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-30 08:48:54 -0600

    public void swapCamera() {
            int index = CAMERA_ID_FRONT;
            if (getCameraIndex() == CAMERA_ID_FRONT)
                index = CAMERA_ID_BACK;
            this.disableView();
            this.setCameraIndex(index);
            this.enableView();
   }
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-21 10:36:16 -0600

Seen: 1,875 times

Last updated: Mar 30 '17