Java 从缓冲图像到数据输出流

Java 从缓冲图像到数据输出流,java,file,Java,File,我想向数据输出流写入一个缓冲图像 我试过的都不管用 例如: BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(baos); try {

我想向数据输出流写入一个缓冲图像

我试过的都不管用

例如:

BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);

final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final DataOutputStream dos = new DataOutputStream(baos);

      try {
          dos.writeByte((DataBufferByte) image.getData().getDataBuffer());
      }finally {
          dos.close();
      }

      baos.writeTo(os);
我无法生成行
dos.writeByte((DataBufferByte)image.getData().getDataBuffer())开始工作

现在,它显示:
类型DataOutputStream中的方法writeByte(int)不适用于参数(DataBufferByte)

该方法使用单个
int
,而不是
DataBufferByte
作为参数:

将一个字节作为1字节值写入基础输出流。如果未引发异常,则写入的计数器将递增1

所以你的代码无法编译

请注意,同样使用int,它不能接受超过1字节大小的值


您需要提取DataBufferByte的字节数组,然后可以使用该方法写入它们。

因此,无法将缓冲图像写入数据输出流?请您提供一个我的例子好吗?我在这里有点不知所措!谢谢