public class Utils {
public static void zoomInImage(String srcPath, String newPath, int maxWidth, int maxHeight) throws Exception {
BufferedImage bufferedImage = null;
File file = new File(srcPath);
bufferedImage = ImageIO.read(file);
if(bufferedImage != null){
bufferedImage = zoomInImage(bufferedImage, maxWidth, maxHeight);
ImageIO.write(bufferedImage, "jpg", new File(newPath));
System.out.println("生成图片完成!");
private static BufferedImage zoomInImage(BufferedImage originalImage, int maxWidth, int maxHeight) {
BufferedImage newImage = new BufferedImage(maxWidth, maxHeight, originalImage.getType());
Graphics g = newImage.getGraphics();
g.drawImage(originalImage, 0, 0, maxWidth, maxHeight, null);
g.dispose();
return newImage;
}
不需要对宽和高进行判断,在传参时直接给定宽高就行了.如width * 2, height * 2,width * 0.6, height * 0.6,如果宽高比例不同,图片失真会比较大,太过放大图片也会明显失真.
1.Linux命令基础知识 linux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的
2.HTTP安全响应头配置之Access-Control-Allow-Origin
3.求一元二次方程的根
4.C++ 智能指针概述
5.SpringFramework介绍