我希望有人可以帮助我,这就是我想要做的.
我有一个JTextPane,我想截取特定的JTextPane坐标和大小,到目前为止,我可以做一个JTextPane大小的截图,但我无法得到我的截图总是得到的特定坐标(0,0 )坐标.
这是我的方法:
void capturaPantalla ()
{
try
{
int x = txtCodigo.getX();
int y = txtCodigo.getY();
Rectangle areaCaptura = new Rectangle(x, y, txtCodigo.getWidth(), txtCodigo.getHeight());
BufferedImage capturaPantalla = new Robot().createScreenCapture(areaCaptura);
File ruta = new File("P:\\captura.png");
ImageIO.write(capturaPantalla, "png", ruta);
JOptionPane.showMessageDialog(null, "Codigo de barras guardado!");
}
catch (IOException ioe)
{
System.out.println(ioe);
}
catch(AWTException ex)
{
System.out.println(ex);
}
}
Run Code Online (Sandbox Code Playgroud)