2013-10-29 44 views
-1

所以做某些动作的问题我做了一些代码,截图功能如何在我的Java项目采取的屏幕截图

现在这是我做了

public void takeScreenshot() { 
     try { 
      Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); 
      Point point = window.getLocationOnScreen(); 
      int x = (int)point.getX(); 
      int y = (int)point.getY(); 
      int w = window.getWidth(); 
      int h = window.getHeight(); 
      Robot robot = new Robot(window.getGraphicsConfiguration().getDevice()); 
      Rectangle captureSize = new Rectangle(x, y, w, h); 
      java.awt.image.BufferedImage bufferedimage = robot.createScreenCapture(captureSize); 
      int picNumber = random(100); 
      String fileExtension = "The Iron Door"; 
      File file = new File((new StringBuilder()).append(SignLink.getCacheDirectory() + "Screenshots/" + fileExtension + " ").append(picNumber).append(".png").toString()); 
      ImageIO.write(bufferedimage, "png", file); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

现在的代码代码完美的作品我有它设置上做热键的操作,现在我有两个问题

1)如何将添加某种它周围的边框是由我预先制作,并在用户需要的屏幕截图将边框放在图像上

2)我会怎么做它使用户可以输入他们想要的截图被称为

回答

3

的名字我将如何使它使用户可以输入自己想要的名字截图被称为

看看JFileChooser

如何将添加某种它周围的边框是由 预先让我当用户采取的截图它把边界 图片

这是一个多一点涉及,将取决于你想达到什么。

开始创建一个新的BufferedImage它的大小与添加到它的边框大小的截图一样...

BufferedImage img = new BufferedImage(bufferedimage.getWidth() + borderSize, bufferedimage.getWidth() + borderSize, BufferedImage.TYPE_INT_RGB); 

从新的BufferedImage一个Graphics背景...

Graphics2D g2d = img.createGraphics(); 

涂料截图吧...

g2d.drawImage(bufferedimage, borderSize/2, borderSize/2, null); 

绘制边框和图形上下文

g2d.dispose(); 

取决于你想要达到什么样的配置,你可以先绘制边框和第二绘制图像,但是这取决于你