Problema ao salvar imagem da webcam

0 respostas
Lucas_Romeo

Fiz o download de um projeto java na qual interage com minha Webcam. Estou tentando adicionar a funcionalidade de tirar fotos através da webcam, ou seja, apenas capturar a imagem atual e salvá-la no C:

Criei um botão chamado Capturar e fiz um ActionListener

startC.addActionListener(new ActionListener()
		{			
			@Override
			public void actionPerformed(ActionEvent e)
			{				
			      // Grab a frame			      
				 FrameGrabbingControl fgc = new FrameGrabbingControl() {
						
						@Override
						public Component getControlComponent() {
							// TODO Auto-generated method stub
							return null;
						}						
						
						@Override
						public Buffer grabFrame() {
							return new Buffer();
						}
					};	
			      player.getControl("javax.media.control.FrameGrabbingControl");	
			      buf = fgc.grabFrame();			      
			
			      // Convert it to an image			      
			      BufferToImage btoi = new BufferToImage((VideoFormat)buf.getFormat());
			      // btoi = new BufferToImage((VideoFormat)buf.getFormat());	
			      img = btoi.createImage(buf);       
			
			      // show the image	
			      //imgpanel.setImage(img);       
			
			      // save image	
			      try {
					saveJPG(img,"c:\\test.jpg");					
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}	
			}
		});

Método saveJPG

public static void saveJPG(Image img, String s) throws IOException	
	  {	    
	    BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
	    File outputfile = new File("C:\\saved.jpg");
	    ImageIO.write(bi, "png", outputfile);
}

O problema é que quando clico em Capturar, está salvando simplesmente uma tela toda preta, e não é isso que a webcam está focando.

Podem me ajudar ?

Criado 25 de setembro de 2012
Respostas 0
Participantes 1