views:

515

answers:

5

Hi, I am writing an application in Java to view images which contain a lot of text and graphics, like a screenshot of a webpage, actually its a image of a magazine article. Some parts are text, some parts are graphics.

My client program is written in Java, I can use any image format, what is the best image compression format I can get my hands on in Java? So I can compress and de-compress?

It would be nice if the image became clearly as it loaded, but thats not necessary, its not 1997 anymore (remember gif loading).

+3  A: 

You haven't supplied one key piece of information: does the compression need to be lossless or is lossy fine? And if lossy is fine withint what tolerance?

You can reduce an entire image to a single bit of information if you're prepared to a highly lossy compression format. :-)

Seriously though, the two main lossless formats are GIF and PNG (both in browser and out of) and the biggest (by far) lossy format is JPG. Other formats like BMP and TIF are nowhere near as efficient.

all three of these formats are well-supported in Java (either directly or with readily-available third party libraries). PNG tends to be better compression ratios than GIF.

See:

cletus
PNG also supports things like alpha transparency and is capable of true-colour, whereas GIF is (I believe?) still limited to 256 colours.
Alistair Knock
It also depends on how long he is willing to spend compressing http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/ :-)
CiscoIPPhone
CiscolPPhone's comments are more along the lines I am thinking, I really want to get the image size down. Some parts of the image such as text, I guess its got to be lossless, however other parts are photos, could be lossy. Could you have a mixed lossy, lossless?
@philip: you then need to clarify what your requirements are in terms of size vs speed.
cletus
+1  A: 

In addition to cletus' points

There are tools like pngout, pngcrush and optipng to still compress the images

Ram
+2  A: 

DjVu (http://djvu.org/) is probably one of the smartest format to compress / store text oriented images. It actually stores the text as text and adds images for backgrounds. This means that you can partily treat your documents as text (full text search, copy/paste of thetext, ...). The viewing part is probably well suported in Java.

The biggest problem is the lack of good free support for encoding the documents. There is some open source tools available, but last time I checked none of them was very user friendly, nor very developer friendly either. There are very good commercial tools, but pretty expensive.

Guillaume
+1  A: 

For lossy compression, you might also want to consider Jpeg 2000. It's much more efficient than standard JPEG compression, especially at very low quality settings, it's relatively widely adopted and there are plenty of coding / decoding libraries out already.

Adrian Grigore
A: 

I prefer PNG for any internet image work I'm doing, as GIF has a limited palette and JPG doesn't handle transparency.

Kurley