小编Lig*_*hts的帖子

为什么我的 BufferedImage 从字节数组返回 null?

基本上,我正在做的是将图像转换为字节数组,对其进行处理,然后在获得字节数组后,将其转换回图像。这是我将字节数组转换为图像的方法。

InputStream in = new ByteArrayInputStream(result); //result is the byte array
BufferedImage bImageFromConvert;
try {
   bImageFromConvert = ImageIO.read(in);
   ImageIO.write(
      bImageFromConvert, watermark_ext, new File(extracted_name_path));
} catch (Exception e) {
   return e.getMessage();
}
Run Code Online (Sandbox Code Playgroud)

现在这段代码非常适用于 PNG 或 JPG 图像,但是当我将它用于 BMP 图像时,它返回一个异常,表示 bImageFromConvert 为空。谁能帮我知道为什么会这样?谢谢大家。

java image

5
推荐指数
1
解决办法
3417
查看次数

标签 统计

image ×1

java ×1