缩略图代表网页上或计算机中图片经压缩方式处理后的小图 ,其中通常会包含指向完整大小的图片的超链接。缩略图用于在 Web 浏览器中更加迅速地装入图形或图片较多的网页。今天,我们就开始java中图像的缩略图的学习。thumbnailator框架的使用: Java三方---->Thumbnailator框架的使用
使用jdk自带bufferedImage
项目结构如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQUAAAEECAIAAACuqLZjAAAf/UlEQVR4nO2d+VsUV7rH+Tvuc5/73Oc+d7y5YzIZY0aUTByjiUTHaMzcJJpkEkeTzmDIMu644cIeja2AC6IoiyAiiErbgogoqAFcI4s2yKYCTbNvBTac+0ND16mqc6qq6fV0v5+nnjzSXafqQM6n6lRXffv1QwAATODnkK2YOruPpOTEHs+MPZ6ZmJrT1z+Av9vS2fd5ZI5DdgQATsUxPmgT0luf13W0NZraGmoq78ceScHffdbeO29DCq0tAHgO9vrQZuzYFRlbXbR7oHbfcO3ewcpI441tR6JD1m+NWb81ZldkbJuxw0YfdBq/AK3Bzn5ZMGgD/DQ6Ozdg6YxOY9+WACaw14ddkbG9LwpRz3XCMjo0+nKwq6uH5oNO4ydGowMfADdirw8bQ+NQZwF5Qchy2aB0fhANNU/ygUfeBwfuCHAnyj4UFRVFRUXR3l279Rgy5pKXsdF5G1IuV9RFpJf8Y895+h7AB8BTUPChsLBw6tSpU6ZMoa3w3bqT6PkpyzLanFaQk7ojLOPHtSk/rk2pqn5+/taTOWuT529K+7XmeXbuPco2SD5oNdgMSjje+H/rNH4BWp02AJ9q+fn5+Vl9sqzKz8v43RjGW2EvCvY7vgXBvvAO4G2xed94M3wmaN0n1hlH+Q44GjkfLDIsW7ZMxoe/a06gxkTUmDj05Ni2XRmx5ypzG0cty8Wm0Q5uzLJaVdvQt2vOUrYh9QHXIEBrkPHBj5/eE+SxjFxswFtf10yMSP5F+f1aO0lsi/dPp8EHvHAdPziLeDZUH6wyLF++XMaHD784ier2D1Yf+Cnk9M/ZdZnVw9Ll6A3TN+t0zc97KNuQm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iYnJFeLGgs0Cx4/IgWyESkSLdgXLTktzXCrrEUt2gVksqkw6YMd9aclmU9qWlqSq5arRS0MNIuKWIt2QYxEE3ygJqfx3aioRS391SGTTYUxH+yuP02bLxHSP5QcKfHfomkMKd5m3YV1DXE6SHJ+kE9Oq6xFTfzVIZNNgTEf7K4/7QE+ECPRUh8Uk9Mqa1FLOwWZbDqM+YDsrT+txgf5XDXVB+HknB5AJUaipT4oJ6fV1aKGTLYtsOeDffWn8Qw0eTKjlKumnx80kstp9eWuidcPhOS0KMOtohY1ZLJtgTEfoP705IEBrwLGfID605MGbk+rgTEfoP70ZIBMtmoY88EC5KcBJ8GkDwDgJMAHAOABHwCA5/8B+vJtR0VKOXAAAAAASUVORK5CYII=" alt="" />
一、 JDKZoomImage.java
package com.huhx.jdk; import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* writer: huhx
*/
public class JDKZoomImage {
public void zoomImage() {
BufferedImage bufferedImage = null;
File file = new File("image/huhx.jpg");
if (file.canRead()) {
try {
bufferedImage = ImageIO.read(file);
bufferedImage = zoomInImage(bufferedImage, 5);
ImageIO.write(bufferedImage, "JPG", new File("image/zoomHuhx.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
} private BufferedImage zoomInImage(BufferedImage bufferedImage, int times) {
int width = bufferedImage.getWidth() / times;
int height = bufferedImage.getHeight() / times; BufferedImage newImage = new BufferedImage(width, height, bufferedImage.getType());
Graphics graphics = newImage.getGraphics();
graphics.drawImage(bufferedImage, 0, 0, width, height, null);
graphics.dispose();
return newImage;
} public static void main(String[] args) {
new JDKZoomImage().zoomImage();
}
}
二、 结果如下,生成图片zoomHuhx.jpg
huhx.jpg 1366 * 768 398KB
zoomHuhx.jpg 273*153 18.4KB
使用thumbnailator框架
thumbnailator包的地址: http://pan.baidu.com/s/1jI8jjfg。humbnailator框架的具体使用,请参见我的另外博客:Java三方---->Thumbnailator框架的使用
ThumbnailatorImage.java的内容如下:
package com.huhx.jdk; import java.io.File;
import java.io.IOException;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.name.Rename; /**
* @author huhx
*/
public class ThumbnailatorImage {
// 根据缩放比缩放图片
public void zoomImageWithScale() {
try {
Thumbnails.of(new File("image/huhx.jpg").listFiles()).scale(0.2).outputFormat("jpg").toFiles(Rename.PREFIX_DOT_THUMBNAIL);
} catch (IOException e) {
e.printStackTrace();
}
} // 根据固定大小缩放图片
public void zoomImageWithSize() {
try {
Thumbnails.of(new File("image/huhx.jpg").listFiles()).size(640, 480).outputFormat("jpg").toFiles(Rename.PREFIX_DOT_THUMBNAIL);
} catch (IOException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
ThumbnailatorImage image = new ThumbnailatorImage();
image.zoomImageWithScale();
image.zoomImageWithSize();
}
}
- thumbnailator框架的使用: Java三方---->Thumbnailator框架的使用