how can i do a button that on and off a camera

edited December 2013 in Android Mode

hi, i'm new in processing hope you can help me. I want to make and camera app in android mode that have 2 button "ON" & "OFF" , so when i press "ON" the camera will on , and "OFF" to off it. i using the ketai camera example, but i don't know how to put the button in. my code :

/**
 * <p>Ketai Sensor Library for Android: http://KetaiProject.org</p>;
 *
 * <p>Ketai Camera Features:
 * <ul>
 * <li>Interface for built-in camera</li>
 * <li></li>
 * </ul>
 * <p>Updated: 2012-10-21 Daniel Sauter/j.duran</p>
 */

import ketai.camera.*;

KetaiCamera cam;

void setup() {
  orientation(LANDSCAPE);
  imageMode(CENTER);
  cam = new KetaiCamera(this, 320, 240, 24);
}

void draw() {
  image(cam, width/2, height/2);
}

void onCameraPreviewEvent()
{
  cam.read();
}

// start/stop camera preview by tapping the screen
void mousePressed()
{
  if (cam.isStarted())
  {
    cam.stop();
  }
  else
    cam.start();
}
void keyPressed() {
  if (key == CODED) {
    if (keyCode == MENU) {
      if (cam.isFlashEnabled())
        cam.disableFlash();
      else
        cam.enableFlash();
    }
  }
}

Answers

  • Do you have trouble with the graphical button or the implementation of the on / off switch? If it is the former, then you can look at some of the examples provided with Processing: Examples > Topics > GUI > Button.

Sign In or Register to comment.