wcl_123
爱笑的王先生丶
2018-11-12 04:15

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

  • thumbnails

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条回答

为你推荐

换一换