Change image dimensions

D

Derek

Hello:

I want to change the dimensions of an image with java, remains in
proportions.

For example, pass to an image of 200x100 pixels to an image of 20x10 pixels.

Thanks a lot.
 
T

Thomas Weidenfeller

Derek said:
I want to change the dimensions of an image with java, remains in
proportions.

For example, pass to an image of 200x100 pixels to an image of 20x10 pixels.

You want to read the API documentation of Image and its common
subclasses, as well as the API documentation of AffineTransform.

For some more fun you could have a look at Sun's Java 2D tutorial, and
the JAI documentation.


/Thomas
 
D

Derek

Hello:

I have seen this APIS, but I have not idea where I must start. Could you
help me?.

I use ImageIcon class to create an image, because I want use this image with
a label.

Sorry, but I´m a beginner ...

Thanks.
 
T

Tor Iver Wilhelmsen

Derek said:
For example, pass to an image of 200x100 pixels to an image of 20x10 pixels.

Look at the filter classes in the java.awt.image package, like
AreaAverageScalingFilter.
 
S

Simon Shearn

Derek said:
Hello:

I want to change the dimensions of an image with java, remains in
proportions.

For example, pass to an image of 200x100 pixels to an image of 20x10 pixels.

Thanks a lot.

Hello -

Something like this should work:

import java.awt.image.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.*;

....

JPEGEncodeParam params;
Image thumb;
thumb = ImageIO.read(new File("foo.jpg"));
thumb = thumb.getScaledInstance(20, 10, Image.SCALE_SMOOTH);

Regards,

Simon

To reply by email, cut the red wire.
 
S

Simon Shearn

Derek said:
Hello:

I want to change the dimensions of an image with java, remains in
proportions.

For example, pass to an image of 200x100 pixels to an image of 20x10 pixels.

Thanks a lot.
Hello -
Something like this should work:

import java.awt.image.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.*;

...

JPEGEncodeParam params;
Image thumb;
int thumbHeight, thumbWidth;

thumb = ImageIO.read(new File("foo.jpg"));
thumbWidth = thumb.getWidth(null) / 10;
thumbHeight = thumb.getHeight(null) / 10;
thumb = thumb.getScaledInstance(thumbWidth, thumbHeight,
Image.SCALE_SMOOTH);

The thumbnails on http://www.setters.demon.co.uk/lundycam/index.html are
generated by code like this.

Regards,

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top