You are on page 1of 4

import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.

Logger; import javax.imageio.ImageIO; import javax.media.format.VideoFormat; import javax.media.util.BufferToImage; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.JOptionPane; /** * @web http://jc-mouse.blogspot.com/ * @author Mouse */ public class video extends javax.swing.JFrame { jmfVideo b = new jmfVideo(); /** Creates new form video */ public video() { initComponents(); this.setTitle("Captura de Imagen desde WebCam "); //formulario al centro de la pantalla this.setLocationRelativeTo(null); //se coloca un layout tipo CAJA VIDEO.setLayout(new javax.swing.BoxLayout(VIDEO, javax.swing.BoxLayout.L INE_AXIS)); //se aade el componente de video VIDEO.add(b.Componente()); imagen.setText(""); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; VIDEO = new javax.swing.JPanel(); MENU = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); IMAGEN = new javax.swing.JPanel(); imagen = new javax.swing.JLabel(); setResizable(false); getContentPane().setLayout(new java.awt.GridBagLayout()); VIDEO.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt. Color(0, 0, 0))); VIDEO.setPreferredSize(new java.awt.Dimension(200, 200)); javax.swing.GroupLayout VIDEOLayout = new javax.swing.GroupLayout(VIDEO) ; VIDEO.setLayout(VIDEOLayout); VIDEOLayout.setHorizontalGroup(

VIDEOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addGap(0, 198, Short.MAX_VALUE) ); VIDEOLayout.setVerticalGroup( VIDEOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addGap(0, 198, Short.MAX_VALUE) ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); getContentPane().add(VIDEO, gridBagConstraints); MENU.setBorder(javax.swing.BorderFactory.createEtchedBorder()); MENU.setPreferredSize(new java.awt.Dimension(140, 200)); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon os_nuevos/IMAGE_CAPTURE.png"))); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Cancelar"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); javax.swing.GroupLayout MENULayout = new javax.swing.GroupLayout(MENU); MENU.setLayout(MENULayout); MENULayout.setHorizontalGroup( MENULayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA DING) .addGroup(MENULayout.createSequentialGroup() .addGroup(MENULayout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING) .addGroup(MENULayout.createSequentialGroup() .addContainerGap() .addComponent(jButton1, javax.swing.GroupLayout.PREFERRE D_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(MENULayout.createSequentialGroup() .addGap(30, 30, 30) .addComponent(jButton2))) .addContainerGap(12, Short.MAX_VALUE)) ); MENULayout.setVerticalGroup( MENULayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA DING) .addGroup(MENULayout.createSequentialGroup() .addContainerGap() .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED, 40, Short.MAX_VALUE)

.addComponent(jButton2) .addGap(33, 33, 33)) ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0); getContentPane().add(MENU, gridBagConstraints); IMAGEN.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt .Color(0, 0, 0))); IMAGEN.setPreferredSize(new java.awt.Dimension(200, 200)); IMAGEN.setLayout(new java.awt.GridBagLayout()); imagen.setText("jLabel1"); imagen.setMaximumSize(new java.awt.Dimension(200, 200)); imagen.setMinimumSize(new java.awt.Dimension(200, 200)); imagen.setPreferredSize(new java.awt.Dimension(200, 200)); IMAGEN.add(imagen, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); getContentPane().add(IMAGEN, gridBagConstraints); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { try { BufferedImage imagen2; JFileChooser fc = new JFileChooser(); imagen2 = (BufferedImage) ImageIO.createImageInputStream(b.getImagen ()); b.capturarImagen(); Icon icono = new ImageIcon(b.getImagen().getScaledInstance(imagen.getWidth(), imagen.getHeight(), Image.SCALE_DEFAULT)); imagen.setIcon(icono); //BufferedImage foto = new BufferedImage(200, 200, imagen.getIcon()) ; //BufferToImage foto2 = new BufferToImage((VideoFormat),imagen.getIc on()); File file = new File("src/FotoSocios/prueba.png"); ImageIO.write( imagen2, "png", file); } catch (IOException ex) { Logger.getLogger(video.class.getName()).log(Level.SEVERE, null, ex); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

this.dispose(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new video().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JPanel IMAGEN; private javax.swing.JPanel MENU; private javax.swing.JPanel VIDEO; private javax.swing.JLabel imagen; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; // End of variables declaration

You might also like