public static void imgCompressByWH(String srcFile, String desFile, int width, int height, Float quality,
                                       boolean isForceWh) {
        try {
            Image srcImg = ImageIO.read(new File(srcFile));
            if (!isForceWh && (srcImg.getHeight(null) < height || srcImg.getWidth(null) < width)) {
                width = srcImg.getWidth(null);
                height = srcImg.getHeight(null);
            }
            //指定目标图片
            BufferedImage desImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            //根据源图片绘制目标图片
            desImg.getGraphics().drawImage(srcImg, 0, 0, width, height, null);
            ImgCompressUtils.encodeImg(desFile, desImg, quality);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public static void imgCompressByWH ( String srcFile , String desFile , int width , int height , Float quality , boolean isForceWh ) { try { Image srcImg = ImageIO . read ( new File ( srcFile ) ) ; if ( ! isForceWh && ( srcImg . getHeight ( null ) < height || srcImg . getWidth ( null ) < width ) ) { width = srcImg . getWidth ( null ) ; height = srcImg . getHeight ( null ) ; } BufferedImage desImg = new BufferedImage ( width , height , BufferedImage . TYPE_INT_RGB ) ; desImg . getGraphics ( ) . drawImage ( srcImg , 0 , 0 , width , height , null ) ; ImgCompressUtils . encodeImg ( desFile , desImg , quality ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
根据指定宽高和压缩质量进行压缩，当isForceWh为false时,如果指定宽或者高大于源图片则按照源图片大小宽高压缩,
当isForceWh为true时,不论怎样均按照指定宽高压缩

@param srcFile   指定原图片地址
@param desFile   指定压缩后图片存放地址，包括图片名称
@param width     指定压缩宽
@param height    指定压缩高
@param quality   指定压缩质量，范围[0.0,1.0]，如果指定为null则按照默认值
@param isForceWh 指定是否强制使用指定宽高进行压缩,true代表强制,false反之