爱笑的王先生丶 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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题