用java将大图片文件转换出小的缩略图文件,要求使用jdk1.4,
大家可以将这段程序代码改为javabean,以便在web环境中使用,
转换出的小缩略图效果不错!
import javax.imageio.imageio;
import javax.imageio.iioexception;
import java.awt.image.bufferedimage;
import java.awt.image;
import java.io.file;
import java.awt.image.affinetransformop;
import java.awt.geom.affinetransform;
public class imgtest {
public static void main (string argv[]) {
try {
file fi = new file("c:/image2.jpg"); //大图文件
file fo = new file("c:/imgtest.jpg"); //将要转换出的小图文件
int nw = 100;
affinetransform transform = new affinetransform();
bufferedimage bis = imageio.read(fi);
int w = bis.getwidth();
int h = bis.getheight();
double scale = (double)w/h;
int nh = (nw*h)/w ;
double sx = (double)nw/w;
double sy = (double)nh/h;
transform.settoscale(sx,sy);
system.out.println(w + " " +h);
affinetransformop ato = new affinetransformop(transform,null);
bufferedimage bid = new bufferedimage(nw,nh,bufferedimage.type_3byte_bgr);
ato.filter(bis,bid);
imageio.write(bid,"jpeg",fo);
} catch(exception e) {
e.printstacktrace();
}
}
}