dcsimg
== playing with pictures ==
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   laeticia_corlean
Posted On:   Friday, October 11, 2002 03:54 AM

hi,


I would like to create thumbnails of pictures in different sizes (only JPG format) using JAVA - Is there a package somewhere I could use or do I have to make something up from scratch -


Any idea welcome :o)

Re: == playing with pictures ==

Posted By:   Dan_J  
Posted On:   Thursday, December 5, 2002 09:13 AM

You can write an easy(ish) tool to load the file, resize it and then save it as a thumbnail, will look something like the code below. The only thing that you'll have to look up is how to make sure that you have waited for the Image to completely load from file before you try to use it.

import java.io.File;

import java.awt.*;

import java.awt.image.BufferedImage;

// Load the JPEG from file
Image thisImage = YourTool.getImage(fileName);

// Scale the thumbnail dimensions so that the thumbnail will
// fit into a thumbnailMaxSize by thumbnailMaxSize square.
double scaleFactor;
if (xDim>yDim)
{
// Scale x then y
scaleFactor = (double)(thumbnailMaxSize) / xDim;
}
else
{
// Scale y first
scaleFactor = (double)(thumbnailMaxSize) / yDim;
}

// Make the thumbnail
BufferedImage bufferedImage = new BufferedImage(
(int)(xDim * scaleFactor),
(int)(yDim * scaleFactor),
BufferedImage.TYPE_INT_RGB);

Graphics g = bufferedImage.getGraphics();
g.drawImage(thisImage, 0, 0, (int)(xDim * scaleFactor), (int)(yDim * scaleFactor), null);

// Now save it
YourTool.saveToJPG(bufferedImage, fileNameWithoutSuffix + THUMBNAIL_SUFFIX);

Re: == playing with pictures ==

Posted By:   Ronnie_Kilsbo  
Posted On:   Monday, November 11, 2002 10:28 AM

This is highly possible with Java Advanced Imaging (JAI). You can find all documentation you need at Sun's java homepage.

It contains the javadoc aswell as tutorials and code examples.

JAI supports JPEG, of course.

Good luck!

About | Sitemap | Contact