Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Resize Image

Hi..
I'm looking for a simple solution, to resize an image.. perferably some method with this effect:

Image oldImage = new ImageImage("..").getImage();
Image newImage = resizeImage( oldImage, 800, 600 );   // 800px wide, 600px high

Anyone? I'm guessing I need to use the AffineTransform.scale(..) for this; but I don't know what sort of argument I would need to pass...

For example:

   AffineTransform tx = new AffineTransform();
   tx.scale(scalex, scaley);

What would the scalex and scaley need to be, in order to scale it down, from 1024x768 to 800x600 (for example)..
Would it be something like this:

   AffineTransform tx = new AffineTransform();
   tx.scale(0.78125, 0.78125);

??

Cheers.
>> IM
0
InteractiveMind
Asked:
InteractiveMind
  • 5
  • 4
2 Solutions
 
zzynxSoftware engineerCommented:
scalex - the factor by which coordinates are scaled along the X axis direction
scaley - the factor by which coordinates are scaled along the Y axis direction
0
 
zzynxSoftware engineerCommented:
scalex = 800 * 1024
scaley = 600 * 768
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zzynxSoftware engineerCommented:
Typo:
scalex = 800 / 1024
scaley = 600 / 768

of course
0
 
objectsCommented:
heres an example showing how to create thumbnails:

http://developer.java.sun.com/developer/TechTips/1999/tt1021.html
0
 
zzynxSoftware engineerCommented:
Which is
>> tx.scale(0.78125, 0.78125);
indeed :°)
0
 
objectsCommented:
you can also use:

Image scaled = image.getScaledInstance(width, height ,Image.SCALE_FAST);
0
 
InteractiveMindAuthor Commented:
Thank you. :)
0
 
zzynxSoftware engineerCommented:
Thanks
0
 
objectsCommented:
no worries :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now