【问题标题】:Saving an BufferedImage to raw bytes将 BufferedImage 保存为原始字节
【发布时间】:2010-03-31 17:36:02
【问题描述】:

您好,我想将 BufferedImage 保存为原始字节 我暂时这样做

InputStream in = new ByteArrayInputStream(fileData);
BufferedImage image = javax.imageio.ImageIO.read(in);
BufferedImage imageModifier = ResizeImage.resize(image, 10, 10);

但我知道我想保存我的文件,所以我不知道如何转换为这样做

FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);
fileOutStream.write(fileData);

谢谢

【问题讨论】:

    标签: java image bufferedimage


    【解决方案1】:

    您的代码令人困惑。为什么有一个名为fileData 的变量,为什么在尝试写入原始字节时使用FileOutputStream? (我假设你的意思是字节数组?)

    如果您真正想要的是将 BufferedImage 保存到文件中,请使用 javax.imageio.ImageIO

    【讨论】:

    • byte[] fileData = newfile.getFileData();当我得到我的 fileData 时,我将转换为 BufferedImage 以调整我的图像大小,当我重新调整我的图像时,我使用 FileOutputStream 写入一个文件夹
    • 好的,然后阅读 ImageIO,这是您所需要的。此外,您不需要使用 newFile.getFileData()。就做InputStream in = new FileInputStream(new File(<path to file>));
    【解决方案2】:

    来自 Java 2D 跟踪:Writing/Saving an Image

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 2012-09-22
      • 2013-03-20
      • 1970-01-01
      • 2011-07-21
      相关资源
      最近更新 更多