It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Scaling image: black box until repainting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Scaling image: black box until repainting" Watch "Scaling image: black box until repainting" New topic
Author

Scaling image: black box until repainting

Rikki Bostelmann
Greenhorn

Joined: Sep 25, 2004
Posts: 8
Hi,

I'm trying to load an image, rescale it, and draw it on a panel.

After loading an Image and using getScaledInstance printed nothing, I read
that one should use BufferedImage. However, the following code produces
only a black box, until forcing a repaint by changing the size of the
window or minimizing.



Why?
Thanks a ton,
Rikki

[ October 02, 2004: Message edited by: Rikki Bostelmann ]
[ October 02, 2004: Message edited by: Rikki Bostelmann ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535

A variation in option two above (xform) is to make the scaled image one time and then render it in paintComponent vis–a–vis scaling it each time it is rendered. The approach shown above is better suited for ongoing image manipulation while this (suggested variation) is better if you do not need to make anymore changes in the scaled image, such as in a background image for a JPanel.
Rikki Bostelmann
Greenhorn

Joined: Sep 25, 2004
Posts: 8
Craig,

that's exactly what I needed, awesome!!!

Thanks,
Rikki
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scaling image: black box until repainting