import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.gif4j.GifEncoder;
/**
* java 图片生产缩略图,需要用到gif4j包
* @author Kaka
*
*/
public class Test {
public static void main(String[] args) throws IOException {
String uploadPath = "D:\\1247038_7c86df6f1e1956f9722b67e33ba6bbaa.jpg";
File file=new File(uploadPath);
BufferedImage img = ImageIO.read(file);
int h = img.getHeight();
int w = img.getWidth();
if(h>=96 && w >=96){
int nw = 96;
int nh = (nw * h) / w;
if(nh>96) {
nh = 96;
nw = (nh * w) / h;
}
FileOutputStream fos=new FileOutputStream(new File("D:\\t.jpg"));
BufferedImage dest = new BufferedImage(nw, nh,BufferedImage.TYPE_4BYTE_ABGR);
dest.getGraphics().drawImage(img,0,0,nw, nh,null);
GifEncoder.encode(dest, fos);
System.out.println("success");
}
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.gif4j.GifEncoder;
/**
* java 图片生产缩略图,需要用到gif4j包
* @author Kaka
*
*/
public class Test {
public static void main(String[] args) throws IOException {
String uploadPath = "D:\\1247038_7c86df6f1e1956f9722b67e33ba6bbaa.jpg";
File file=new File(uploadPath);
BufferedImage img = ImageIO.read(file);
int h = img.getHeight();
int w = img.getWidth();
if(h>=96 && w >=96){
int nw = 96;
int nh = (nw * h) / w;
if(nh>96) {
nh = 96;
nw = (nh * w) / h;
}
FileOutputStream fos=new FileOutputStream(new File("D:\\t.jpg"));
BufferedImage dest = new BufferedImage(nw, nh,BufferedImage.TYPE_4BYTE_ABGR);
dest.getGraphics().drawImage(img,0,0,nw, nh,null);
GifEncoder.encode(dest, fos);
System.out.println("success");
}
}
}