aspose file tools*
The moose likes Java in General and the fly likes Image Resizing Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Image Resizing Help" Watch "Image Resizing Help" New topic
Author

Image Resizing Help

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Hello;

I am trying to resize an existing image. Below is the code I have been working on. Right now the resized images are the same as the original?

I find this process confusing. There are too many different objects to handle images and it doesn't seem very easy to change from one to another.

If anyone can give any advise as to why my current code is not working, I would greatly appreciate it.

Thanks,

Luke



Luke
SCJP
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You are close

Change the lines :

to


And


to


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Hi Carl,

Thanks for your reply.

Made the change. The image is resized better, but it shows up inside of orginal. What I mean by this is I see a black box the size of the original with a smaller version of the image in the upper left corner. This is the thumbnail.

What am I doing wrong?

Below is the code I was using before. It resized to 100 X 100 but the images were all distored.

There has to be a version of this code between these two that I have posted that does the job.


Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
I think I have got it. Just need to do some test of some longer and wider images to make sure the resize is working out.

Code now is:

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Well this code works fine now, in Windows...

In Linux this line:

GraphicsDevice gs = ge.getDefaultScreenDevice();

Kicks up a HeadlessException.

Any ideas why?

Thanks,

Luke
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
Are your $DISPLAY environment variable and "xhost +" permissions set OK?

In other words, can you successfully pop up an "xclock -bg blue" in the same terminal window as you're trying to run your Java app in (assuming, of course, you're compiling from the command line instead of some graphical IDE)?


Paul M. Santa Maria, SCJP
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
What is happening here is a servlet is calling the code from the class below. The class below is resizing the pic and then returning the path on the server it wrote it too back to the servlet.


[ August 13, 2005: Message edited by: Luke Shannon ]
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Here is the solution:

http://javaalmanac.com/egs/java.awt.image/Image2Buf.html

I had assembled the code above from something I read on another message board. This seems to be the source and deals with the exception.

Luke
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image Resizing Help
 
Similar Threads
Image Resizing Woes
Image to BufferedImage converter
Headless Exception in Linux
works on WinXP jdk 1.6 but not Linux jdk 1.5
lagging on loading image