zoukankan      html  css  js  c++  java
  • 处理图片缩放和旋转。

        Thumbnailator是一个用来生成图像缩略图的 Java类库,通过很简单的代码即可生成图片缩略图,也可直接对一整个目录的图片生成缩略图。

        有了这玩意,就不用在费心思使用Image I/O API,Java 2D API等等来生成缩略图了。

        Thumbnailator的下载地址:

        http://code.google.com/p/thumbnailator/downloads/list

    好了,直接上代码:

    /**  
         *   
         * @throws IOException   
         * @brief 生成缩略图简单实例   
         *  
         */ 
        public static void simple() throws IOException{  
                //需要转换的文件为桌面上的1.png  
                Thumbnails.of("C:/Documents and Settings/Administrator/桌面/1.png")  
                /*  
                 * forceSize,size和scale必须且只能调用一个  
                 */ 
    //          .forceSize(400, 400)  //生成的图片一定为400*400  
                /*  
                 * 若图片横比200小,高比300小,不变  
                 * 若图片横比200小,高比300大,高缩小到300,图片比例不变  
                 * 若图片横比200大,高比300小,横缩小到200,图片比例不变  
                 * 若图片横比200大,高比300大,图片按比例缩小,横为200或高为300  
                 */ 
                .size(200, 300)     
                .outputFormat("png") //生成图片的格式为png  
                .outputQuality(0.8f) //生成质量为80%  
    //          .scale(0.5f)  //缩小50%  
                //输出到桌面5文件  
                .toFile("C:/Documents and Settings/Administrator/桌面/2");  
        }  
          
        /**  
         *   
         * @throws IOException   
         * @brief 生成旋转的缩略图  
         *  
         */ 
        public static void rotate() throws IOException{  
            Thumbnails.of("C:/Documents and Settings/Administrator/桌面/1.png")  
            //顺时针旋转90度  
            .rotate(90)  
            .scale(0.8f)  
            .toFile("C:/Documents and Settings/Administrator/桌面/3");  
        }  
          
        /**  
         *   
         * @brief 生成带水印的图片  
         *  
         * @throws IOException  
         */ 
        public static void watermark() throws IOException {  
            Thumbnails.of("C:/Documents and Settings/Administrator/桌面/1.png")  
            //水印在右下角,50%透明度,水印图片为桌面上的logo.gif  
            .watermark(Positions.BOTTOM_RIGHT,ImageIO.read(new File("C:/Documents and Settings/Administrator/桌面/logo.gif")),0.5f)  
            .scale(0.8f)  
            .toFile("C:/Documents and Settings/Administrator/桌面/4");  
        } 
  • 相关阅读:
    HTML Strip Char Filter
    Creating a custom analyzer in ElasticSearch Nest client
    elasticsearch-analysis-pinyin
    ElasticSearch安装拼音插件 elasticsearch-analysis-pinyin
    Elasticsearch5.4 删除type
    Performs the analysis process on a text and return the tokens breakdown of the text
    Elasticsearch 5 Ik+pinyin分词配置详解
    线性可分支持向量机--SVM(1)
    感知机分类(perceptron classification)
    创建DateFrame的常用四种方式
  • 原文地址:https://www.cnblogs.com/kong0it/p/3016770.html
Copyright © 2011-2022 走看看