0

I am working with a java application project. 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. 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?

rebeliagamer
  • 1,257
  • 17
  • 33
  • Read about image resizing (i.e. http://stackoverflow.com/questions/14115950/quality-of-image-after-resize-very-low-java ). Also consider sending ready image in correct size without resizing it inside the application. – rebeliagamer Oct 17 '13 at 13:25
  • 1
    SCALE_SMOOTH method may be helpful to you. [Image.SCALE_SMOOTH](http://docs.oracle.com/javase/7/docs/api/java/awt/Image.html#SCALE_SMOOTH) – Prasad Oct 17 '13 at 13:31

1 Answers1

0

If you use a downscaled version of an image for an Icon, the resolution loss cannot be compensated when printing the 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). This can be done by applying an AffineTransform/Scale prior to drawing the Image, or by using graphics.drawImage(x,y,width,height,imageObserver).

Peter Walser
  • 15,208
  • 4
  • 51
  • 78