Utils.java
957 Bytes
package com.viontech.match.util;
import java.awt.*;
import java.awt.image.BufferedImage;
/**
* .
*
* @author 谢明辉
* @date 2020/11/23
*/
public class Utils {
public static BufferedImage convertImg2Jpg(BufferedImage image) {
BufferedImage newBufferedImage;
//防止图片变色
int width = image.getWidth();
int height = image.getHeight();
if (width > 600 || height > 600) {
newBufferedImage = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = newBufferedImage.createGraphics();
graphics.drawImage(image, 0, 0, 600, 600, Color.WHITE, null);
} else {
newBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = newBufferedImage.createGraphics();
graphics.drawImage(image, 0, 0, Color.WHITE, null);
}
return newBufferedImage;
}
}