# Open Android Camera

**URL:** <https://discourse.processing.org/t/open-android-camera/23696>\
**Category:** Processing for Android\
**Created:** [September 5, 2020, 5:18pm UTC](https://discourse.processing.org/t/open-android-camera/23696 "2020-09-05T17:18:33Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 31, 2020, 4:25pm UTC](https://discourse.processing.org/t/open-android-camera/23696/10 "2020-12-31T16:25:23Z")

</div>

if not this should get it working

```auto
import ketai.camera.*;
boolean mdown = false;
int counter = 0;

KetaiCamera cam;

void setup() {
  orientation(LANDSCAPE);
  cam = new KetaiCamera(this, 1280, 768, 30);
  println(cam.list()); // 1
  // 0: back camera; 1: front camera
  cam.setCameraID(0); // 2
  imageMode(CENTER);
  stroke(255);
  textSize(48); // 3
}

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

void drawUI() { // 1
  fill(0, 128);
  rect(0, 0, width/4, 100);
  rect(width/4, 0, width/4, 100);
  rect(2*(width/4), 0, width/4, 100);
  rect(3*(width/4), 0, width/4, 100);
  fill(255);
  if (cam.isStarted()) // 2
    text("stop", 20, 70);
  else
    text("start", 20, 70);
  text("camera", (width/4)+20, 70);
  text("flash", 2*(width/4)+20, 70);
}
void mousePressed() { // 3
  if (mouseY <= 100) { // 4
    if (mouseX > 0 && mouseX < width/4) { // 5
      if (cam.isStarted())
      {
        cam.stop();
      }
      else
      {
        if (!cam.start())
          println("Failed to start camera.");
      }
    }
    else if (mouseX > width/4 && mouseX < 2*(width/4)) // 6
    {
      int cameraID = 0;
      if (cam.getCameraID() == 0)
        cameraID = 1;
      else
        cameraID = 0;
      cam.stop();
      cam.setCameraID(cameraID);
      cam.start();
    }
    else if (mouseX >2*(width/4) && mouseX < 3*(width/4)) // 7
    {
      if (cam.isFlashEnabled()) // 8
        cam.disableFlash();
      else
        cam.enableFlash();
    }
  }
}
void onCameraPreviewEvent() {
  cam.read();
}
void exit() {
  cam.stop();
}

void logic(){
  if(mousePressed&&!mdown){
      mdown = true;
      counter++;
      println(counter);
    }
    
    if(!mousePressed)mdown = false;
    if(counter>6)counter = 0;
};

```

note this only works from pc build, not apde.

---

_[View the full topic](https://discourse.processing.org/t/open-android-camera/23696)._
