我正在尝试截取JPanel后面的内容,但保存后会得到黑色图像。
以下是代码:
private void takeScreenshot(String print){
JFileChooser c = new JFileChooser(getRealDesktop());
FileFilter jpg = new FileNameExtensionFilter(".jpg", ImageIO.getReaderFileSuffixes());
FileFilter jpeg = new FileNameExtensionFilter(".jpeg", ImageIO.getReaderFileSuffixes());
FileFilter png = new FileNameExtensionFilter(".png", ImageIO.getReaderFileSuffixes());
c.setFileFilter(png);
c.setFileFilter(jpeg);
c.setFileFilter(jpg);
c.showSaveDialog(this);
if(c.getSelectedFile() != null){
String ssLoc = c.getSelectedFile().getAbsolutePath()+c.getFileFilter().getDescription();
System.out.println(ssLoc);
BufferedImage bufImg = new BufferedImage(ssWindow.getSize().width, ssWindow.getSize().height,BufferedImage.TYPE_INT_RGB);
ssWindow.paint(bufImg.createGraphics());
File imageFile = new File(ssLoc);
try{
imageFile.createNewFile();
ImageIO.write(bufImg, "JPG", imageFile);
}catch(Exception ex){
System.err.println(ex);
}
}
}
按下操作按钮如下所示:
this.setVisible(false);
takeScreenshot("ssTake");
this.setVisible(true);
如何使这项工作?
答案 0 :(得分:1)
谢谢,Gilbert Le Blanc。
我为了使用机器人重新编写了一些代码,现在代码看起来像这样:
let cipherText = UnsafeMutablePointer<UInt8>(cipherData.mutableBytes)