簡體   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