我EOFException
在尝试Bitmap
使用 RLE 压缩图像时遇到问题。我基本上采用位图图像的字节数组,然后对第 54 个字节之后的所有内容执行 RLE 压缩,因为这都是头文件的内容。然后我使用BMPImageReader
读取新的字节数组,然后BMPImageWriter
将其保存为新的 RLE8 压缩位图。
但是在该部分
File file = new File("runLength.txt");
...
BMPImageWriteParam imageWriteParam = new BMPImageWriteParam();
imageWriteParam.setCompressionMode(2);
imageWriteParam.setCompressionType("BI_RLE8");
imageWriteParam.setTopDown(true);
BMPImageWriter bmpImageWriter = (BMPImageWriter) ImageIO.getImageWritersByFormatName("bmp").next();
FileImageOutputStream output = new FileImageOutputStream(file);
bmpImageWriter.setOutput(output);
BMPImageReader bmpImageReader = (BMPImageReader) ImageIO.getImageReader(bmpImageWriter);
ImageInputStream iis = ImageIO.createImageInputStream(bais);
bmpImageReader.setInput(iis);
ImageReadParam param = bmpImageReader.getDefaultReadParam();
imageRLE = bmpImageReader.read(0, param);
它在最后一行抛出异常。我已经逐步完成了代码,它很好地传递了标头,但是在读取第一个字节时抛出了异常(我认为......这有点难以理解)。
这是堆栈跟踪:
java.io.EOFException
at javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:353)
at com.sun.imageio.plugins.bmp.BMPImageReader.read24Bit(BMPImageReader.java:1227)
at com.sun.imageio.plugins.bmp.BMPImageReader.read(BMPImageReader.java:882)
at cs24010.RLECompression.stringToImage(RLECompression.java:139)
at cs24010.RLECompression.compress(RLECompression.java:63)
at cs24010.RLECompression.run(RLECompression.java:219)
at java.lang.Thread.run(Thread.java:745)
有谁知道可能导致错误的原因?