google使用的开源的工具类Thumbnailator图像处理
<dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailator</artifactId> <version>0.4.8</version></dependency>Thumbnails.of("images/a380_1280x1024.jpg").size(200, 300).toFile("c:/a380_200x300.jpg");
2、按照比例进行缩放
Thumbnails.of("images/a380_1280x1024.jpg").scale(0.25f).toFile("c:/a380_25%.jpg");
3、不按照比例,指定大小进行缩放
//keepAspectRatio(false) 默认是按照比例缩放的
Thumbnails.of("images/a380_1280x1024.jpg").size(200,200).keepAspectRatio(false).toFile("c:/a380_200x200.jpg");
4、旋转
Thumbnails.of("images/a380_1280x1024.jpg").size(1280,1024).watermark(Positions.BOTTOM_RIGHT,ImageIO.read(newFile("images/watermark.png")),0.5f).outputQuality(0.8f).toFile("c:/a380_watermark_bottom_right.jpg");
6、裁剪
//图片中心400*400的区域
Thumbnails.of("images/a380_1280x1024.jpg").sourceRegion(Positions.CENTER,400,400).size(200,200).keepAspectRatio(false).toFile("c:/a380_region_center.jpg");
Thumbnails.of("images/a380_1280x1024.jpg").size(1280,1024).outputFormat("png").toFile("c:/a380_1280x1024.png");
OutputStream os = new FileOutputStream("c:/a380_1280x1024_OutputStream.png");
Thumbnails.of("images/a380_1280x1024.jpg").size(1280,1024).toOutputStream(os);
9、输出到BufferedImage
//asBufferedImage()返回BufferedImage
BufferedImage thumbnail=Thumbnails.of("images/a380_1280x1024.jpg").size(1280,1024).asBufferedImage();
ImageIO.write(thumbnail,"jpg",newFile("c:/a380_1280x1024_BufferedImage.jpg"));
google使用的开源的工具类Thumbnailator图像处理的更多相关文章
- 开源JDBC工具类DbUtils
本篇将会详细地介绍Apache公司的JDBC帮助工具类DbUtils以及如何使用.在上一篇中我们已经通过将以前对dao层使用JDBC操作数据库的冗余代码进行了简易封装形成自己的简单工具类JdbcUti ...
- [Google Guava] 强大的集合工具类:java.util.Collections中未包含的集合工具
转载的,有问题请联系我 原文链接 译文链接 译者:沈义扬,校对:丁一 尚未完成: Queues, Tables工具类 任何对JDK集合框架有经验的程序员都熟悉和喜欢java.util.Collecti ...
- Google Guava学习笔记——基础工具类Joiner的使用
Guava 中有一些基础的工具类,如下所列: 1,Joiner 类:根据给定的分隔符把字符串连接到一起.MapJoiner 执行相同的操作,但是针对 Map 的 key 和 value. 2,Spli ...
- Google Guava学习笔记——基础工具类Preconditions类的使用
Preconditions类是一组静态方法用来验证我们代码的状态.Preconditons类很重要,它能保证我们的代码按照我们期望的执行,如果不是我们期望的,我们会立即得到反馈是哪里出来问题,现在我们 ...
- Google Guava学习笔记——基础工具类针对Object类的使用
Guava 提供了一系列针对Object操作的方法. 1. toString方法 为了方便调试重写toString()方法是很有必要的,但写起来比较无聊,不管如何,Objects类提供了toStrin ...
- Google Guava学习笔记——基础工具类String处理类的使用
不管你喜欢何种编程语言,很多时候针对string编程的处理都是乏味而且爱出错误的,很多时候,我们需要从文件或是数据库中读取数据,或者根据需求重新格式化或排序字符串给用户显示.幸运的是,Guava提供了 ...
- Google Guava学习笔记——基础工具类Splitter的使用
另一项经常对字符串的操作就是根据指定的分隔符对字符串进行分隔.我们基本上会使用String.split方法: String testString = "Monday,Tuesday,,Thu ...
- StringUtils 字符串工具类
package com.thinkgem.jeesite.common.utils; import java.io.File; import java.io.IOException; import j ...
- GSON工具类
import java.util.Map; import com.google.gson.reflect.TypeToken; import com.google.gson.FieldNamingPo ...
随机推荐
- Linux大文件分割splite
/********************************************************************** * Linux大文件分割splite * 说明: * 编 ...
- Python之路,第五篇:Python入门与基础5
python 循环语句 作用: 根据一定的条件,重复的执行一个或多个语句 两种循环语句: while 语句 for 语句 while 语句: 语法: while 真值表达式: 语句1 ... ...
- tarfile — Read and write tar archive files
参考: https://docs.python.org/2/library/tarfile.html http://www.jianshu.com/p/bbad16822eab #解压文件tarfil ...
- MyBatis sql语句使用总结
MyBatis中Like语句使用总结 oracle数据库: SELECT * FROM user WHERE name like CONCAT('%',#{name},'%') 或 : SELECT ...
- 容器(container)
一.容器有哪些 平时我们经常看到各种容器名称:Servlet容器.WEB容器.Java WEB容器.Java EE容器等 二.容器是什么 2-1 容器通常理解就是装东西的,我们这里说技术上的容 ...
- How to generate a new dictionary file of mmseg
How to generate a new dictionary file of mmseg 0.Usage about mmseg-node memtioned in github : var mm ...
- LeetCode - Diameter of Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...
- s3c2410串口笔记
- Generic Realtime Intermediary Protocol
转自:https://pushpin.org/docs/protocols/grip/ Introduction The Generic Realtime Intermediary Protocol ...
- Space Shooter 学习
using UnityEngine; using System.Collections; /// <summary> /// 背景滚动 /// </summary> publi ...