# Dynamic get(); method in Ketai library?

**URL:** https://discourse.processing.org/t/dynamic-get-method-in-ketai-library/30899
**Category:** Processing for Android
**Created:** [June 25, 2021, 1:28am UTC](https://discourse.processing.org/t/dynamic-get-method-in-ketai-library/30899 "2021-06-25T01:28:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![thorj](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@thorj](https://discourse.processing.org/u/thorj)
#### Post date: [June 25, 2021, 1:28am UTC](https://discourse.processing.org/t/dynamic-get-method-in-ketai-library/30899/1 "2021-06-25T01:28:22Z")

</div>

Hello,

I’m new in Processing, and I try to create some funny pixelator app on Android APDE using camera on my Phone. To solve this task I’m using a Ketai library. Problem is when I try to get image from camera using get() method^ I got only one frame as an image, not a video stream from my camera. But I need a realtime video stream from my camera. Who can help me to understand how can I do it. The code is here:

```auto
import ketai.camera.*;

KetaiCamera cam; 

color bg = #f1f1f1;
color fg = #111111;
PImage img;

void setup() { 
  requestPermission("android.permission.WRITE_EXTERNAL_STORAGE", "checkPermission");
  size(displayWidth, displayHeight);
  orientation(LANDSCAPE); 
  imageMode(CENTER); 
  cam = new KetaiCamera(this, displayWidth, displayHeight, 24);
  cam.setCameraID(0);
  background(bg);
} 

void draw() { 

    background(bg);
    fill(fg);

    if (mousePressed == true) {
      cam.start();
    } else {
      cam.stop();
    }
    
    img = cam.get();
    

    float tileX = map(mouseY, 0, height, 10, 100);
    //float tileY = ratio * tileX;
    float tileSize = width / tileX;

    for (int y = 0; y < img.height; y += tileSize) {
      for (int x = 0; x < img.width; x += tileSize) {

        color c = img.get(x, y);
        float b = map(brightness(c), 0, 255, 1, 0);

        pushMatrix();
        translate(x, y);
        rect(0, 0, b * tileSize, b* tileSize);
        popMatrix();
      }
    }
}

void checkPermission(boolean wasPermissionGranted) { 
  if (wasPermissionGranted) println("Hooray! I can now write to the local file system!"); 
  else println("Oh no! I was not granted write permission =(");
}

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();
    }
  }
}

```

Thank you)

---

<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: [June 26, 2021, 8:16am UTC](https://discourse.processing.org/t/dynamic-get-method-in-ketai-library/30899/2 "2021-06-26T08:16:47Z")

</div>

simple ketai sketch

> **Summary**
>
> ```auto
> import android.os.Environment;
> import android.os.Build ;
> import android.app.Activity;
> import android.content.Context;
> 
> boolean k1 = false;
> int W = 1440, H = 720;
> Permission storage, camera, readStorage;
> PGraphics canvas;
> PShader edges;
> KetaiCamera cam;
> 
> //void settings(){
> // //size(W,H,P2D);
> //};
> 
> void setup() {
> fullScreen(P2D);
> orientation(LANDSCAPE);
> cam = new KetaiCamera(this, width, height, 60);
> canvas = createGraphics(W, H, P2D);
> //edges = loadShader("edges.glsl");
> storage = new Permission(this, "WRITE_EXTERNAL_STORAGE");
> readStorage = new Permission(this, "READ_EXTERNAL_STORAGE");
> camera = new Permission(this, "CAMERA");
> //cam.start();
> };
> 
> void draw() {
> fill(255);
> background(0);
> if (frameCount>10&&!cam.isStarted())cam.start();
> image(cam, 0,0);
> text(frameRate, 50, 100);
> };
> 
> void mousePressed() {
> //if (cam.isStarted()){
> // cam.stop();
> //}else cam.start();
> 
> if (cam.isFlashEnabled())
> cam.disableFlash();
> else
> cam.enableFlash();
> };
> 
> void onCameraPreviewEvent() {
> cam.read();
> };
> 
> ```

> **Summary**
>
> ```auto
> class AndroidAcamera {
> 
> AndroidAcamera() {
> };
> 
> void display() {
> //if(BMS.menus.get(0).items.get(1).toggle==1){
> canvas.beginDraw();
> 
> //mult = BMS.Sliders.get(0).value;
> //counter = BMS.Sliders.get(1).value;
> //mult = 1.0;
> //counter = 1.0;
> //edges.set("mult",mult);
> //edges.set("type",counter);
> canvas.shader(edges);
> canvas.fill(0);
> canvas.rect(0, 0, width, height);
> canvas.imageMode(CENTER);
> canvas.image(cam, width/2, height/2+20);
> canvas.imageMode(CORNER);
> canvas.fill(0);
> canvas.rect(0, 0, width, 20);
> canvas.endDraw();
> //}
> };
>   
> void start(){
> if (frameCount>10&&!cam.isStarted())cam.start();
> };
> };
> 
> ```

> **Summary**
>
> ```auto
> public class Permission{
>   
> PApplet parent;
> String p;
>   
> public boolean requestedPortraitImage = false;
> 
> public Permission(PApplet pParent,String permissionName) {
> parent = pParent;
> p = permissionName;
> parent.requestPermission("android.permission."+permissionName, "onPermissionResult", this);
> println(permissionName);
> };
> 
> public void onPermissionResult(boolean granted) {
> if (!granted) {
> PApplet.println("User did not grant ",p, "permission. Camera is disabled.");
> }
> };
> 
> };
> 
> ```

---

<div class="post-metadata">

### Author: ![thorj](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@thorj](https://discourse.processing.org/u/thorj)
#### Post date: [June 26, 2021, 12:03pm UTC](https://discourse.processing.org/t/dynamic-get-method-in-ketai-library/30899/3 "2021-06-26T12:03:37Z")

</div>

Hello, please can you explain your solution in few words

---

<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: [June 26, 2021, 3:39pm UTC](https://discourse.processing.org/t/dynamic-get-method-in-ketai-library/30899/4 "2021-06-26T15:39:40Z")

</div>

Just take it one line at a time my friend.
