java Thumbnailator压缩图片不改变尺寸 | 您所在的位置:网站首页 › thumbnailator下载 › java Thumbnailator压缩图片不改变尺寸 |
scale:指定图片的大小,值在0到1之间,1f就是原图大小,0.5就是原图的一半大小,这里的大小是指图片的长宽。 outputQuality:图片的质量,值也是在0到1,越接近于1质量越好,越接近于0质量越差。 原图片尺寸不变,质量压缩 outputQuality public class PictureTest { public String imgParent = "src/main/resources/images/"; @Test public void originWidth() throws IOException { Thumbnails.of(imgParent+"flower.jpg").scale(1).outputQuality(0.1).toFile(imgParent + "width_flower.jpg"); } } 原图:8.29MBhttps://gitee.com/lhy102/compress_picture/tree/master/ size(width,height):图片宽高比。 keepAspectRatio(false):默认是按照比例缩放的。 rotate:角度,正数:顺时针,负数:逆时针。 watermark:添加水印,参数(水印位置,水印图,透明度)。 sourceRegion:图片裁剪,参数(裁剪位置, 宽, 高)。 outputFormat:输出的图片格式。 toOutputStream:输出到OutputStream。 forceSize:压缩至指定图片尺寸(例如:横400高300) |
CopyRight 2018-2019 实验室设备网 版权所有 |