爱笑的王先生丶 2018-11-12 04:15 采纳率: 0%
浏览 2589

Thumbnails图片压缩 一直报Unsupported Image Type 但是重启一下就好了,请教什么问题

Thumbnails.of(new InputStream[] { new ByteArrayInputStream(original) }).size(w, h).toOutputStream(baos);

             @RequestMapping({"/image"})

public void image(HttpServletResponse resp, @RequestParam(value="path", defaultValue="") String filePath, @RequestParam(value="group", defaultValue="") String group, @RequestParam(value="w", defaultValue="") Integer width, @RequestParam(value="h", defaultValue="") Integer height, @RequestParam(value="type", defaultValue="") String compressType)
{
logger.debug("loading img file '{}'", filePath);
if (StringUtils.isEmpty(filePath))
{
resp.setStatus(404);
return;
}
boolean successed = false;
FastdfsStorage storage = null;
try
{
storage = this.fastdfsContext.getStorage();
byte[] bytes = storage.downFile(group, filePath);
if (bytes != null)
{
if ((width != null) && (height != null) && (width.intValue() >= 0) && (height.intValue() >= 0)) {
bytes = DefaultImageCompresserFactory.get(compressType).deal(bytes, width.intValue(), height.intValue());
}
resp.setHeader("Content-Length", Integer.toString(bytes.length));

    resp.getOutputStream().write(bytes);
    successed = true;
  }
}
catch (FastdfsException e)
{
  logger.debug("loading fastdfs file  group#'{}' file#'{}' fail", new Object[] { group, filePath, e });
}
catch (IOException e)
{
  logger.debug("response write error : {}", e.getMessage(), e);
}
catch (CompressException e)
{
  logger.debug("image bytes compress fail ", e);
}
finally
{
  if (storage != null) {
    storage.close();
  }
}
if (!successed) {
  resp.setStatus(404);
}

}

  • 写回答

1条回答

  • threenewbee 2018-11-12 15:45
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试