简体   繁体   English

如何在Java Swing中制作高质量的图像图标?

[英]how can i make high quality image icon in java swing?

I am working with a java application project. 我正在使用Java 应用程序项目。 I want to make an image as icon in my JPanel but it seems to be low quality image when i am printing the image using the external printer. 我想在JPanel中将图像制作为图标,但是当我使用外部打印机打印图像时,它似乎是低质量的图像。 Here is the code 这是代码

    ImageIcon ii=new ImageIcon(scaleImage(90, 107, ImageIO.read(new File(f.getAbsolutePath()))));
    image.setIcon(ii);

How can I make high quality image icon other than this method? 除此方法外,如何制作高质量的图像图标?

If you use a downscaled version of an image for an Icon , the resolution loss cannot be compensated when printing the icon. 如果为Icon使用图像的缩小版本,则在打印图标时无法补偿分辨率损失。

Instead of using ImageIcon , you can create your own icon class (by implementing the javax.swing.Icon interface, it's actually quite simple), which keeps your Image at a higher resolution and paints it at a smaller size (but without quality loss, so you still can see more detail when printing it). 除了使用ImageIcon ,您还可以创建自己的图标类(通过实现javax.swing.Icon接口,它实际上非常简单),这样可以使Image保持较高的分辨率,并以较小的尺寸进行绘制(但不会降低质量,因此您仍可以在打印时看到更多详细信息)。 This can be done by applying an AffineTransform /Scale prior to drawing the Image, or by using graphics.drawImage(x,y,width,height,imageObserver) . 这可以通过在绘制图像之前应用AffineTransform / Scale或使用graphics.drawImage(x,y,width,height,imageObserver)

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

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