简体   繁体   English

Java中的BMP图像压缩和解压缩

[英]BMP Image Compression and Decompression in java

I am searching for a way to compress and decompress a BMP Image in java. 我正在寻找一种在Java中压缩和解压缩BMP图像的方法。

I found an easy way using javax.imageio , like the following tutorial . 我找到了使用javax.imageio的简单方法,就像下面的教程一样

using the following two classes ( ImageWriter , ImageWriteParam ) , but the example provided is just compressing an Image . 使用以下两个类( ImageWriterImageWriteParam ),但是提供的示例只是压缩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 . 也欢迎任何其他压缩BMP的解决方案。

Thanks in Advance. 提前致谢。

The simplest ways to read and write images in Java using ImageIO, is just using the read and write static methods directly. 使用ImageIO在Java中读取和写入图像的最简单方法是直接使用readwrite静态方法。

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 . 分别使用ImageReaderImageReadParam以及ImageWriterImageWriteParam (如本教程所述),可以更好地控制要解码图像的哪些部分,大小或区域,或诸如压缩类型,编码质量等格式特征, 如果您愿意需要它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM