Hi!
I'm trying to zoom in/out ImageIcon in JLabel. The problem is that after 2-3 zooming actions, the image quality becomes horrible. How could I solve this problem? Thanks!
private void doZoom(int scaleFactor) {
Component[] c = SelectablePanel.getMainPanel().getComponents();
for(int i = 0; i < c.length; i++) {
if(c[i] instanceof JLabel) {
JLabel selectedLabel = (JLabel)c[i];
ImageIcon newIcon = (ImageIcon) selectedLabel.getIcon();
Image img = newIcon.getImage();
Image newImg = img.getScaledInstance(img.getWidth(null)+scaleFactor, img.getHeight(null)+scaleFactor, java.awt.Image.SCALE_SMOOTH);
selectedLabel.setPreferredSize(new Dimension(img.getWidth(null)+scaleFactor, img.getHeight(null)+scaleFactor));
newIcon = new ImageIcon(newImg);
selectedLabel.setIcon(newIcon);
}
}
repaint();
}