Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamResolution;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
/**
 *
 * @author PC_hacking
 */
public class CampCap extends javax.swing.JFrame {
 
    private Dimension ds = new Dimension(450,360);
    private Dimension cs = WebcamResolution.VGA.getSize();
    private Webcam wCam = Webcam.getDefault();
    private WebcamPanel wCamPanel = new WebcamPanel(wCam, ds, false);
    /**
     * Creates new form CampCap
     */
    public CampCap() {
        initComponents();
        wCam.setViewSize(cs);
        wCamPanel.setFillArea(true);
        panelCam.setLayout(new FlowLayout());
        panelCam.add(wCamPanel);
 
    }
 
 
 
 
    private void btStartActionPerformed(java.awt.event.ActionEvent evt) {                                        
        Thread r = new Thread(){
            @Override
            public void run(){
            wCamPanel.start();
            }
        };
        r.setDaemon(true);
        r.start();
    }                                       
 
    private void btCaptureActionPerformed(java.awt.event.ActionEvent evt) {                                          
        try {
            File file = new File(String.format("capture-%d.jpg", System.currentTimeMillis()));
            ImageIO.write(wCam.getImage(), "JPG", file);
            JOptionPane.showMessageDialog(this, "image Capturer avec succé:\n"+file.getAbsolutePath(), "CampCap", 1);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(this, "erreur de capture :\n"+e.getMessage(), "CamCap", 0);
        }
    }                                         
 
    /**
     * @param args the command line arguments
     */
 
        //</editor-fold>
 
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CampCap().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton btCapture;
    private javax.swing.JButton btStart;
    private javax.swing.JPanel pCapture;
    private javax.swing.JPanel panelCam;
    // End of variables declaration                   
}