How to decrease the size of image using a java peogram

Hi All,

I want to decrease the size of an image from MB to KB. I have some images of size around 1MB to 3MB. While displaying all those images in the browser it is taking so much time to download all those and display. So I want to write a Java program to make a duplicate copies of those images, which are small in height and width and display those images in small size. Basically I need to display all the list of images as thumbnail view or list view with faster speed.

Thanks in advance..

Upendra P.

[529 byte] By [Upendra.Pa] at [2007-10-3 4:15:36]
# 1
Read the documentation of java.awt.Image class.
hiwaa at 2007-7-14 22:17:06 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for your reply hiwa..I read the documentation. There is no corresponding Image class. The other classes are like BufferedImage and all. For those there is no such option called setHeight() and setWidth(). It will be great if you give me some sample code?
Upendra.Pa at 2007-7-14 22:17:06 > top of Java-index,Java Essentials,Java Programming...
# 3

> I read the documentation. There is no corresponding Image class. The other

> classes are like BufferedImage and all.

Yes BufferedImage sounds like what you want.

You could (1) Read the image (2) Obtain its dimensions and create a blank

scaled image (3) Draw a scaled version of the original image using the

Graphics2D obtained from the smaller one. (4) Save the smaller image.

The javax.util.ImageIO class will help with reading and writing the data and

Sun's Tutorial has a section on "2D Graphics".

pbrockway2a at 2007-7-14 22:17:06 > top of Java-index,Java Essentials,Java Programming...
# 4

> Thanks for your reply hiwa..

> I read the documentation. There is no corresponding

> Image class. The other classes are like BufferedImage

> and all. For those there is no such option called

> setHeight() and setWidth().

> It will be great if you give me some sample code?

The java.awt.Image class has getScaledInstance() method.

I thought it was what you want.

hiwaa at 2007-7-14 22:17:06 > top of Java-index,Java Essentials,Java Programming...
# 5

Thanks for the explanation pbrockway2 ..

but I am not able to create an object for the BufferedImage class. There is no constructor for that which reads the path of the original Image. I guess that there is some other option. I want some sample code for this. I will be very much thanksful to you if you give me that...

Thanks in advance..

Upendra.Pa at 2007-7-14 22:17:06 > top of Java-index,Java Essentials,Java Programming...
# 6
Hi pbrockway2 and hiwa,I have completed the task successfully. Thanks for your replies.
Upendra.Pa at 2007-7-14 22:17:06 > top of Java-index,Java Essentials,Java Programming...