Foros del Web » Programación para mayores de 30 ;) » Java »

ayuda con capturar pantalla en java

Estas en el tema de ayuda con capturar pantalla en java en el foro de Java en Foros del Web. hola tengo esta clase que captura la pantalla y la pone en un label , pero cuando va poner la segunda imagen me sale un ...
  #1 (permalink)  
Antiguo 25/06/2010, 15:28
Avatar de RIVERMILLOS  
Fecha de Ingreso: marzo-2010
Mensajes: 1.336
Antigüedad: 14 años, 2 meses
Puntos: 15
ayuda con capturar pantalla en java

hola tengo esta clase que captura la pantalla y la pone en un label , pero cuando va poner la segunda imagen me sale un error esta es la clase..

Código:
import java.awt.AWTException;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
 
class CapturarPantalla {
int x=1;
Main m;
public CapturarPantalla(Main m){
	this.m=m;
}
public int captura() throws HeadlessException, AWTException, IOException{
	
    BufferedImage pantalla = new Robot().createScreenCapture(
    new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
    
    File file = new File("src/pantalla"+x+".jpg");
    ImageIO.write(pantalla, "jpg", file);
    ImageIcon tmpIconAux = new ImageIcon(getClass().getResource("src/pantalla"+x+".jpg"));
   mageIcon tmpIcon = new ImageIcon(tmpIconAux.getImage().getScaledInstance(950, -5, Image.SCALE_DEFAULT));
   this.m.label.setIcon(tmpIcon);
    this.m.label.validate();
  
    x++;
    return 1;
}	
public static void main(String args[]){
     
   }
}
main es otra clase que genera lo grafico.
Código:
public static void main(String arg[]){Main m=new Main();objeto= new CapturarPantalla(m)}

@Override
public void actionPerformed(ActionEvent arg0) {
try {
objeto.captura();
}catch (HeadlessException e) {
e.printStackTrace();
}catch (AWTException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}	
}
este es el error
Código:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at javax.swing.ImageIcon.<init>(Unknown Source)
	at CapturarPantalla.captura(CapturarPantalla.java:26)
	at Main.actionPerformed(Main.java:42)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
que puede ser
saludos

Etiquetas: pantalla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:24.