/*
OLDSRC: Original picture address folder such as ' d:/'
NEWSRC: Compressed image address folder such as ' e:/'
Widthdist,heightdist: Width and height after compression
Createtime 2010-11-25
@auto Yijianfeng
*/
Public void Reduceimgall (String oldsrc, string newsrc, int widthdist,
int heightdist) {
try {
File File = new file (OLDSRC);
if (!file.exists ()) {
return;
}
file[] srcfile = File.listfiles ();
if (srcfile! = null) {
for (int i = 0; i < srcfile.length; i++) {
if (Srcfile[i].isfile ()
&& (Srcfile[i].getname (). EndsWith (". jpg")
| | srcfile[i].getname (). EndsWith (". JPG ")
| | | srcfile[i].getname (). EndsWith (". gif") | | srcfile[i]
. GetName (). EndsWith (". gif"))) {
Image src = javax.imageio.ImageIO.read (srcfile[i]);
bufferedimage tag = new BufferedImage ((int) widthdist,
(int) heightdist, bufferedimage.type_int_rgb);
tag.getgraphics (). DrawImage (
src.getscaledinstance (widthdist, Heightdist,
Image.scale_smooth), 0, 0, null);
FileOutputStream out = new FileOutputStream (newsrc
+ srcfile[i].getname ());
JPEGImageEncoder encoder = Jpegcodec
. Createjpegencoder (out);
System.out.println (oldsrc + "/" + srcfile[i].getname ());
Encoder.encode (tag);
out.close ();
} else {
Reduceimgall (oldsrc + srcfile[i].getname (), NEWSRC,
widthdist, heightdist);
}
}
}
} catch (IOException ex) {
ex.printstacktrace ();
}
}
Copyright NOTICE: This article for Bo Master http://www.zuiniusn.com original article, without Bo Master permission not reproduced.
Java Picture Batch compression + all compression