繁体   English   中英

如何在 java 中获得较少像素化的屏幕截图?

[英]How can I get a less pixelated screenshot in java?

从 JFrame 捕获图像后,我在 java 中使用了BufferedImage 我需要一些方法来锐化图像,以便在放大时看起来不会那么像素化。 这是它必须保持相同图像大小的事情。

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

    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;
        }
    }

这是它创建的图像在此处输入图像描述

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

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

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

我认为这是因为您将其写为 JPEG 文件。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM