It seems even when I use BI_RLE4, I get the same issue. However, with the other string types, BI_RGB and BI_BITFIELDS the program runs fine. Can someone explain this cos I don't understand the problem.
Thanks in advance
Glen Chamisa wrote:It seems even when I use BI_RLE4, I get the same issue. However, with the other string types, BI_RGB and BI_BITFIELDS the program runs fine. Can someone explain this cos I don't understand the problem.
I don't know a whole lot about the BMP format, but the javadoc for javax.imageio.plugins.bmp.BMPImageWriteParam says, "If the specified compression scheme is not compatible with the type of image being written then the IOException will be thrown by the BMP image writer." It sounds like this is happening.
You might want to try calling getCompressionTypes() on your BMPImageWriteParam and examine what it returns. I can't say for sure that this would be helpful, but it might be.
There appears to be a bit more to this then you may realize as noted here
stackoverflow.com wrote:Note that BI_RLE8 compression is not available for all types of BufferedImages.
For exmaple BI_RLE8 compression is supported for BufferedImage.TYPE_BYTE_INDEXED and BufferedImage.TYPE_BYTE_GRAY but it
is not supported for BufferedImage.TYPE_3BYTE_BGR in which case an IOException will be thrown by the ImageWriter.write() method
(which is actually BMPImageWriter.write()).
That being said, I came across this site https://www.programcreek.com/java-api-examples/index.php?api=javax.imageio.ImageTypeSpecifier which lead me to create the following code:
This does appear to create a new file, which in my case is call newcake.bmp. Possibly this code will help you out.
Please, when posting code like you did in your initial posting, provide the full code with the correct imports.
Sometimes the problem with the code is that the incorrect imports are included.