爱笑的王先生丶 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 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿