BMP Image Compression and Decompression in java

1.4k views Asked by At

I am searching for a way to compress and decompress a BMP Image in java.

I found an easy way using javax.imageio , like the following tutorial .

using the following two classes (ImageWriter , ImageWriteParam) , but the example provided is just compressing an Image .

what i am looking for is use the same classes and the same mechanism to decompress "my compressed image" that i got from the provided example .

Is there anyway to do this with same mechanism ?

any other solution to compress a BMP are also welcome .

Thanks in Advance.

1

There are 1 answers

0
Harald K On

The simplest ways to read and write images in Java using ImageIO, is just using the read and write static methods directly.

Read:

BufferedImage image = ImageIO.read(new File("input.bmp"));

Write:

BufferedImage image = ...; // from disk or created in memory, etc

if (!ImageIO.write(image, "BMP", new File("output.bmp"))) {
    // TODO: Handle not written case
}

Using the ImageReader and ImageReadParam, and ImageWriter and ImageWriteParam respectively (as in the tutorial), gives more control over what parts of the image to decode, size or region, or format features such as compression type, quality to encode etc., if you need it.