Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image Resizing Help

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are close

Change the lines :

to


And


to
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic