askJava
asked on
convert jpg and gif to thumbnails?
Hi,
Can anyone help me with a java class to convert jpg and gif to thumbnails. The function including resize the pic ratio. I am thinking if convert to thumbnails might be slow then I can use the resize ratio to resize the pic to certain ratio displaying on the web page.
I don't know how to calculate the resize ratio.
Thanks.
Can anyone help me with a java class to convert jpg and gif to thumbnails. The function including resize the pic ratio. I am thinking if convert to thumbnails might be slow then I can use the resize ratio to resize the pic to certain ratio displaying on the web page.
I don't know how to calculate the resize ratio.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I still didn't get the problem fix but thanks for your help.
ASKER
Hi object, your answer is right. I own you more 100 points. Next time I will ask another simple question and will assign the 100 points to you. thanks.
ASKER
Sorry for the delay. Had a family emergency. I did the following but got an error message:
Exception in thread "main" java.lang.IllegalArgumentE
ght (0) cannot be <= 0
at java.awt.image.DirectColor
n Source)
at java.awt.image.BufferedIma
at test.<init>(test.java:25)
at test.main(test.java:11)
How u initialize the W?
int W = 0;
File file=new File(".");
File thumb = new File(file.getParentFile(),
Image i = new ImageIcon(file.getCanonica
int w = i.getWidth(null);
int h = i.getHeight(null);
double ratio = (double) W / (double) w;
AffineTransform scale = AffineTransform.getScaleIn
BufferedImage scaled = new BufferedImage(W, (int)(h*ratio), BufferedImage.TYPE_INT_RGB
Graphics2D g = scaled.createGraphics();
g.setTransform(scale);
g.drawImage(i, 0, 0, null);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncode
JPEGEncodeParam jpegParams = encoder.getDefaultJPEGEnco
jpegParams.setQuality(1.0f
encoder.setJPEGEncodeParam
encoder.encode(scaled);