@Slf4j public class ImageUtils { /** * 图片压缩处理 * @param origPicContent * @return */ public static String compressPic(String origPicContent) { ByteArrayInputStream in = null; ByteArrayOutputStream out = null; try { byte[] bytes = new BASE64Decoder().decodeBuffer(origPicContent); in = new ByteArrayInputStream(bytes); out = new ByteArrayOutputStream(); Thumbnails.of (in).scale(0.3f).toOutputStream(out); return new BASE64Encoder().encode( out.toByteArray ()); } catch (IOException e) { log.error ("decode buffer fail, message:{}", e.getMessage (), e); } finally { if (in != null) { try { in.close (); } catch (IOException e) { log.error ("ByteArrayInputStream close fail, message:{}", e.getMessage (), e); } } if (out != null) { try { out.close (); } catch (IOException e) { log.error ("ByteArrayOutputStream close fail, message:{}", e.getMessage (), e); } } } return origPicContent; }
}