(If this is the wrong place to send this kind of message I apologize in
advance --
please let me know where to redirect my query and I'll not bother you again)
I'm planning to build a servlet that will auto-generate thumbnails of
the pics at my site, but am failing miserably with the scale transform.
Can someone please tell me what I'm doing wrong here?
One other strange thing -- I think I'm setting things to maintain maximum
quality in the output image, but I'm ending up with an image that is 1/20
the size (on disk) as the original. That sounds like some pretty aggressive
JPEG compression to me ...
To make it easier I boiled my code down to a short program.
================= BEGIN CODE ================
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.io.*;
import com.sun.image.codec.jpeg.*;
public class ImageTest
{
public static void main(String args[])
{
try
{
// Why isn't the result of this program a JPEG file that is
// half the height and width of the original?
// Of course, a 2nd question is why is the picture 1/20 the
// size on the disk while still being the same image height
// & width when I used "setQuality" to max on the output
// quality ....
InputStream in = new FileInputStream("jm.jpg");
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
BufferedImage inputImage = decoder.decodeAsBufferedImage();
BufferedImageOp scaleFilter =
new
AffineTransformOp(AffineTransform.getScaleInstance(.5f,.5f),null);
BufferedImage scaledImage = scaleFilter.filter(inputImage, null);
OutputStream out = new FileOutputStream("jm-small.jpg");
JPEGEncodeParam parms = JPEGCodec.getDefaultJPEGEncodeParam(scaledImage);
parms.setQuality(1f,false);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(scaledImage);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".