After I rotate a BufferedImage, I still see the old one.
I can flip (vertical, and horizontal) an image but when I try to scale or rotate it, the old image is still showing up. I’ve tried every repaint, remove, removeall, etc that I can think of but still have double vision! :o
Note that if I resize the window large enough ( just a little movement won’t do it) then the old image does go away!
Here is the code that I use to rotate a loaded BufferedImage:
public static BufferedImage rotateImage(BufferedImage bi)
{
BufferedImage new_bi = new BufferedImage( bi.getHeight(),
bi.getWidth(),
bi.getType());
Graphics2D g2d = new_bi.createGraphics();
AffineTransform at = g2d.getTransform();
AffineTransform rotation = new AffineTransform();
rotation.rotate(Math.PI / 2, bi.getWidth() / 2, bi.getHeight() / 2);
g2d.transform(rotation);
g2d.drawImage( bi,
null,
bi.getWidth() / 2 - new_bi.getWidth() / 2,
(bi.getHeight() / 2 - new_bi.getHeight() / 2) * -1);
g2d.setTransform(at);
return new_bi;
}
The code that displays the new BufferedImage that is returned from the rotateImage method looks like this
private void displayBufferedImage(BufferedImage bif)
{
jpMainPanel = new JPanel();
jpMainPanel.setLayout(new BorderLayout());
jpMainPanel.setOpaque(false);
setTitle(“Display Program”);
if(jlBackground != null)
{
//This doesn’t help…but I tried it
getLayeredPane().remove(jlBackground);
getLayeredPane().repaint();
this.getContentPane().removeAll();
this.repaint();
}
jlBackground = new JLabel();
ImageIcon backImage = new ImageIcon(bif);
jlBackground.setIcon(backImage);
jlBackground.setBounds(0, 0, backImage.getIconWidth(), backImage.getIconHeight());
getLayeredPane().add(jlBackground, new Integer(Integer.MIN_VALUE));
setContentPane(jpMainPanel);
//Tried all of the following too…no help
jlBackground.repaint();
getLayeredPane().repaint();
jpMainPanel.repaint();
this.repaint();
this.getContentPane().repaint();
}
I think if I can get the Rotate to work, then the scale will follow the same principle.
Can anyone help me cure my double vision please?