zoukankan      html  css  js  c++  java
  • java生成缩略图

    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");


    }
    }
  • 相关阅读:
    2018第45周日
    RabbitMQ消息的消费与持久化
    Rabbitmq的调度策略
    Rabbitmq交换器Exchange和消息队列
    RabbitMQ概念
    微服务拆分
    微服务演化
    2018第44周日
    福勒(Martin Fowler)
    微服务架构定义那点事
  • 原文地址:https://www.cnblogs.com/macula7/p/1960401.html
Copyright © 2011-2022 走看看