I am trying to scale an image with AffineTransform. However, the image does not appear correctly when the Frame appears initially.
But after the frame is resized, the image shows perfectly.
Here is the code.
public class MainFrame extends javax.swing.JFrame {
Line line;
BufferedImage bi;
public MainFrame() {
initComponents();
try {
bi = ImageIO.read(new File("map.png"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
AffineTransform old = g2.getTransform();
g2.scale(0.25, 0.25);
g2.drawImage(bi, 0, 0, null);
g2.setTransform(old);
}
...
}