saving image from camera using ketai library

edited February 2016 in Android Mode

hello again guys ,so i made this simple app (has a little bug),i wanted to know is their any way i could save image when i clicked a button somewhere in a screen ,if thats is possible i want to transmit live video from one camera device to another which is using same app,through wifi services ,so i am not an experienced android programmer and therefore ANY HELP WILL BE APPRECIATED SO I ADDED MY CODE BELOW!!

import ketai.camera.*; import ketai.ui.*; import ketai.sensors.*; KetaiCamera cam; KetaiSensor sensor; KetaiVibrate vibe; float accelerometerX, accelerometerY, accelerometerZ; PImage camera; PImage start; PImage second;

float i,j; float speedx=random(0,0.1); float speedy=random(0,0.1); void setup() { sensor = new KetaiSensor(this); vibe = new KetaiVibrate(this); sensor.start(); camera=loadImage("140157940.bmp"); start=loadImage("910414892.bmp.jpg"); second=loadImage("279053025.bmp"); size(540,480); //camera=new PImage("140157940.BMP"); //background(camera); orientation(LANDSCAPE); textSize(25); // vibe = new KetaiVibrate(this); } void onCameraPreviewEvent() { cam.read(); } void draw() { if(millis()<4000) {background(start); } else if(millis()>4000&&millis()<8000) {background(second); fill(255,0,0); text("do not attempt dangerous",width/2-20,height/2+20); }

else {

display(); cameraa(); ellipsemove(); //keyboard(); } }

void savePhoto(String filename) { cam.addToMediaLibrary(filename); }

void mousePressed() { if(mouseY<100) {

if (mousePressed&&mouseX>0&&mouseX<70) KetaiKeyboard.toggle(this);

else if (mousePressed&&mouseX > width/3 && mouseX < width-(width/3)) { KetaiAlertDialog.popup(this, "Pop Up!", "Shadow at your service"); } else if(mouseX> width-(width/3)&&mouseX<width&&mousePressed) { vibe.vibrate(1000);

} } }

void ellipsemove() { ellipse(i,j,20,20); i= displayWidth/2; j=displayHeight/2; i=i+speedx; j=j+speedy; speedx= speedx+2accelerometerY; speedy= speedy+2accelerometerX; i=constrain(i,101,displayWidth-20); j=constrain(j,71,displayHeight-20); accelerometerX=0; accelerometerY=0;
}

void onAccelerometerEvent(float x, float y, float z) { accelerometerX = x; accelerometerY = y; accelerometerZ = z; }

void display() { //text("Camera",5,height/3); // background(0); if(cam != null && cam.isStarted()) image(cam,160,85,352,288);

else
{

pushStyle(); background(camera);

//textAlign(LEFT); //fill(0); stroke(255); line(0, 70, width,70); line(100, 0, 100,480); line(width,0,width,70); line( width-(width/3),0, width-(width/3),70); line(0,height/3+20,100,height/3+20);

//line((width/3)*2, 0, width/3, 100);

fill(0,0,255); textSize(12); text("Camera",5,height/3); text("Accelerometer",5,2height/4); text("Keyboard", 5, 60); text("PopUp", width/3 + 5, 60); text("Vibrate", width/32 + 5, 60); text("Accelerometer: \n" + "x: " + nfp(accelerometerX, 1, 3) + "\n" + "y: " + nfp(accelerometerY, 1, 3) + "\n" + "z: " + nfp(accelerometerZ, 1, 3),5,2*height/4 ); fill(#0FFAE8);

textSize(15); text("Developer",300,400); text("tarkesh2shar",350,425);

popStyle(); } }

void cameraa() {

if(mousePressed && mouseX>0 && mouseX<55&&mouseY>155&&mouseY<175) { if(cam == null) cam = new KetaiCamera(this,640,480, 24);

if (cam.isStarted()) { cam.stop(); } else cam.start(); } }

Answers

  • `import ketai.camera.*; import ketai.ui.*; import ketai.sensors.*; KetaiCamera cam; KetaiSensor sensor; KetaiVibrate vibe; float accelerometerX, accelerometerY, accelerometerZ; PImage camera; PImage start; PImage second;

    float i,j; float speedx=random(0,0.1); float speedy=random(0,0.1); void setup() { sensor = new KetaiSensor(this); vibe = new KetaiVibrate(this); sensor.start(); camera=loadImage("140157940.bmp"); start=loadImage("910414892.bmp.jpg"); second=loadImage("279053025.bmp"); size(540,480); //camera=new PImage("140157940.BMP"); //background(camera); orientation(LANDSCAPE); textSize(25); // vibe = new KetaiVibrate(this); } void onCameraPreviewEvent() { cam.read(); } void draw() { if(millis()<4000) {background(start); } else if(millis()>4000&&millis()<8000) {background(second); fill(255,0,0); text("do not attempt dangerous",width/2-20,height/2+20); }

    else {

    display(); cameraa(); ellipsemove(); //keyboard(); } }

    void savePhoto(String filename) { cam.addToMediaLibrary(filename); }

    void mousePressed() { if(mouseY<100) {

    if (mousePressed&&mouseX>0&&mouseX<70) KetaiKeyboard.toggle(this);

    else if (mousePressed&&mouseX > width/3 && mouseX < width-(width/3)) { KetaiAlertDialog.popup(this, "Pop Up!", "Shadow at your service"); } else if(mouseX> width-(width/3)&&mouseX<width&&mousePressed) { vibe.vibrate(1000);

    } } }

    void ellipsemove() { ellipse(i,j,20,20); i= displayWidth/2; j=displayHeight/2; i=i+speedx; j=j+speedy; speedx= speedx+2accelerometerY; speedy= speedy+2accelerometerX; i=constrain(i,101,displayWidth-20); j=constrain(j,71,displayHeight-20); accelerometerX=0; accelerometerY=0;
    }

    void onAccelerometerEvent(float x, float y, float z) { accelerometerX = x; accelerometerY = y; accelerometerZ = z; }

    void display() { //text("Camera",5,height/3); // background(0); if(cam != null && cam.isStarted()) image(cam,160,85,352,288);

    else
    {
    

    pushStyle(); background(camera);

    //textAlign(LEFT); //fill(0); stroke(255); line(0, 70, width,70); line(100, 0, 100,480); line(width,0,width,70); line( width-(width/3),0, width-(width/3),70); line(0,height/3+20,100,height/3+20);

    //line((width/3)*2, 0, width/3, 100);

    fill(0,0,255); textSize(12); text("Camera",5,height/3); text("Accelerometer",5,2height/4); text("Keyboard", 5, 60); text("PopUp", width/3 + 5, 60); text("Vibrate", width/32 + 5, 60); text("Accelerometer: \n" + "x: " + nfp(accelerometerX, 1, 3) + "\n" + "y: " + nfp(accelerometerY, 1, 3) + "\n" + "z: " + nfp(accelerometerZ, 1, 3),5,2*height/4 ); fill(#0FFAE8);

    textSize(15); text("Developer",300,400); text("tarkesh2shar",350,425);

    popStyle(); } }

    void cameraa() {

    if(mousePressed && mouseX>0 && mouseX<55&&mouseY>155&&mouseY<175) { if(cam == null) cam = new KetaiCamera(this,640,480, 24);

    if (cam.isStarted()) { cam.stop(); } else cam.start(); } }

    `

  • You'll get a better response if you format your code. Here's how:

    http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text

Sign In or Register to comment.