This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Scale a BufferedImage.   (Solved) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Scale a BufferedImage.   (Solved)" Watch "Scale a BufferedImage.   (Solved)" New topic

Scale a BufferedImage. (Solved)

Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
I have created a buffered image
Then I construct my GUI as a frame with three panels. The one on which the image is to be displayed is coded:
The image I'm working with is big, 4004 pixels by 2762 lines, and all that displays is the upper right hand corner. I want to scale it by a factor of 1/3 to fit on my display before displaying it.
I've looked at couple of APIs but I'm new at this and I'm missing something and I don't know how to use the hash table in this context.

It took a lot of searching and trials but I found a way by creating a class that extends JPanel and putting the code in it;

In my GUI setup:

It all appears to work now (at least to scale an image down) and I can retrieve the pixel values (16 bit gray scale) under the tool tip from the original data.
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
The above works but is not quite correct if one wants to print or save the image. I found the save image had the reduced size image in the upper right corner of the original image! Here's corrected code.

I agree. Here's the link:
subject: Scale a BufferedImage. (Solved)
It's not a secret anymore!