直接上代码:
public static String compressPicForScale(String imagePath, long minFileSize, long maxFileSize)
{
LOGGER.debug("开始执行图片压缩【compressPicForScale】");
LOGGER.info("当前的文件路径为:" + imagePath + "设置的尺寸标准为大于:" + minFileSize + "kb" + "小于" + maxFileSize + "kb");
BASE64Encoder encoder = new BASE64Encoder();
byte[] data = getBytesFromHost(imagePath);
LOGGER.info("原始图片大小=======" + data.length);
if ((data.length <= minFileSize * 1024L) && (data.length < maxFileSize * 1024L))
return encoder.encode(data);
long srcSize = data.length;
double accuracy = getAccuracy(srcSize / 1024L);
try {
while (data.length > maxFileSize * 1024L) {
ByteArrayInput