First time here? Check out the FAQ!

Ask Your Question
0

How to add a button to switch between cameras

asked May 21 '13

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.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Mar 30 '17

    public void swapCamera() {
            int index = CAMERA_ID_FRONT;
            if (getCameraIndex() == CAMERA_ID_FRONT)
                index = CAMERA_ID_BACK;
            this.disableView();
            this.setCameraIndex(index);
            this.enableView();
   }
Preview: (hide)

Question Tools

Stats

Asked: May 21 '13

Seen: 1,911 times

Last updated: Mar 30 '17