Hello my friends, I made an algorithm in which I have two buttons, one to take photo and one to save the photo taken.
I purposely did that, because I like to complicate things, you understand me, right? haha ha
The issue is that when I click on my take photo button I use a capture.get and pass this to a variable.
The problem is that when using this, my camera capture stops even though I re-call the variable capture and giving capture.loop to it again.
I was able to work around this problem by calling createCapture again and passing it back to my capture variable.
I do not know if it is the only possible solution, I would like something to make the camera return to normal after capture.get without using this method that I used to get around this situation, as it ends up adding more videos to the html.
I would like you to have a capture.start option or to have the capture.loop option work
Here is the code running online for you to look at as it was:
https://aprendendomais.000webhostapp.com/TirarFotoComButtonESalvar/
NOTE: You must have camerâ on the pc.
And here’s the code:
var capture;
var buttonTirarFoto;
var buttonSalvarFoto;
var fotoTirada;
var modo = 0;
var confirmarTakeSnap = false;
function setup() {
createCanvas(windowWidth, windowHeight);
capture = createCapture(VIDEO);
capture.hide();
buttonTirarFoto = createButton("Tirar Foto");
buttonTirarFoto.position(width/2, height - 60);
buttonTirarFoto.mousePressed(takeSnap);
buttonSalvarFoto = createButton("Salvar Foto");
buttonSalvarFoto.position(width/2 - 100, height - 60);
buttonSalvarFoto.mousePressed(saveSnap);
}
function draw() {
if(modo == 0){
image(capture, width/2 + 25, 0);
}else if(modo == 1){
background(255);
image(fotoTirada, 0, 0, width, height);
saveCanvas("minhaFoto", "jpg");
background(255);
modo = 0;
}
}
function takeSnap(){
image(capture, 20, 0);
fotoTirada = capture.get();
image(fotoTirada, 20, 0);
capture = createCapture(VIDEO);
capture.hide();
confirmarTakeSnap = true;
}
function saveSnap(){
if(confirmarTakeSnap){
modo = 1;
}
}
NOTE: You must import the DOM library to run the code.
Hugs!