2011-06-10 65 views
2

我在从JFrame中捕获图像后,在java中使用BufferedImage我需要一些方法来锐化图像,以便当它放大时它看起来不像那么像素化。这是它保持相同的图像大小的事情。如何在java中获得更少的像素化屏幕截图?

这是我用来捕获图像的代码。

private void grabScreenShot() throws Exception 
    { 
     BufferedImage image = (BufferedImage)createImage(getSize().width, getSize().height); 
     paint(image.getGraphics()); 
     try{ 
      //ImageIO.write(image, "jpg", new File(TimeTable.path+"\\TimeLine.jpg")); 
      ImageIO.write(image, "jpg", new File("C:\\Users\\"+TimeTable.user+"\\AppData\\TimeLineMacroProgram\\TimeLine.jpg")); 
      //ImageIO.write(image, "jpg", new File("C:\\ProgramData\\TimeLineMacroProgram\\TimeLine.jpg")); 
      System.out.println("Image was created"); 
     } 
     catch (IOException e){ 
      System.out.println("Had trouble writing the image."); 
      throw e; 
     } 
    } 

下面是它创建 enter image description here

+1

我不使用Swing,所以这可能是关闭的。但它不完美吗?例如以SCREEN分辨率捕捉(这可能不足以满足您的需求)? – MJB 2011-06-10 22:04:40

回答

4

JPG不适合截图。它专为复杂和丰富多彩的图片而设计,其中压缩过程中的信息丢失几乎可以忽略不计,如照片。对于屏幕截图,您应该使用GIF或更好的PNG。

ImageIO.write(image, "png", new File("C:\\Users\\"+TimeTable.user+"\\AppData\\TimeLineMacroProgram\\TimeLine.png")); 

你只会得到一个更大的文件,但你得到像素完美的清晰度和细节,这是根本不可能与JPG。

1

我想这是因为你写它作为一个JPEG文件的图像。

我会将格式更改为非有损格式,否则会强制作者不通过访问和更改其ImageWriteParam来使用压缩。

+0

目前,它将允许我使用的最佳压缩类型 – 2011-06-10 20:59:07