图像如何在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;
}
}
这是它创造的图像
# 1 楼答案
JPG不适合截图。它是为复杂多彩的图片设计的,在压缩过程中,信息损失几乎可以忽略不计,比如照片。对于屏幕截图,你应该使用GIF或者更好的PNG
你只会得到一个更大的文件,但你会得到完美的像素清晰度和细节,这在JPG中是不可能的
# 2 楼答案
我想这是因为你把它写成了JPEG文件
我会将格式更改为非有损格式,或者通过访问和更改其ImageWriteParam来强制编写器不使用压缩