如何在 Java 中进行 LZW 解码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2424998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 21:05:04  来源:igfitidea点击:

How can I do LZW decoding in Java?

javadecodinglzw

提问by Andrei Vajna II

I have a database which contains picture data stored as a binary blob. The documentation says the data is encoded using LZW. I thought that I could decode it using the Zip or GZip input streams found in the Java library, but it didn't work - I got an exception that said the format of the data is not correct.

我有一个数据库,其中包含存储为二进制 blob 的图片数据。文档说数据是使用 LZW 编码的。我以为我可以使用 Java 库中的 Zip 或 GZip 输入流对其进行解码,但它不起作用 - 我收到一个异常,表示数据格式不正确。

From what I've read, the library uses DEFLATE, which is not LZW. Also, I've read about some licensing problems for using the LZW algorithm.

从我读过的内容来看,该库使用的是 DEFLATE,而不是 LZW。另外,我已经阅读了有关使用 LZW 算法的一些许可问题。

What can I use to decode the data? Is there a library? Do I have to implement it myself? What about the licensing problems?

我可以用什么来解码数据?有图书馆吗?我必须自己实施吗?牌照问题怎么办?

采纳答案by Stephen C

Here are a couple of links:

这里有几个链接:

And there are others.

还有其他人。

Indeed if the images are LZW compressed TIFF files, The Java Advanced Imaging APIapparently supports decoding directly (though not encodingit seems).

事实上,如果图像是 LZW 压缩的 TIFF 文件,Java Advanced Imaging API显然支持直接解码(尽管似乎没有编码)。

回答by Thomas Levesque

I know the question is old, but I just wanted to add a great resource about LZW:

我知道这个问题很老,但我只是想添加一个关于 LZW 的很棒的资源:

http://www.matthewflickinger.com/lab/whatsinagif/lzw_image_data.asp

http://www.matthewflickinger.com/lab/whatsinagif/lzw_image_data.asp

It's more specifically about the use of LZW in GIF images, but it explains the compression and decompression algorithms pretty well.

更具体地说,是关于 LZW 在 GIF 图像中的使用,但它很好地解释了压缩和解压缩算法。

回答by Carlos Tasada

You can also try with 7-Zip JBindingwhich uses the 7zip library internally. It's quite easy to use.

您还可以尝试使用内部使用 7zip 库的7-Zip JBinding。它很容易使用。

回答by Henrik Aasted S?rensen

I went through a surprising amount of LZW implementations before finding one that worked for my case.

在找到适合我的案例之前,我经历了数量惊人的 LZW 实现。

UncompressedInputStreamfrom the BioJava projectworked for me, when I needed to unpack a .pax file.

UncompressedInputStreamBioJava项目工作对我来说,当我需要一个解压文件.pax。