Skip to main content

Image compression...

4 replies [Last post]
jedusan
Offline
Joined: 2008-10-15
Points: 0

How can I reduce an image file size without losing quality in J2ME?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

There is really no way to compress without the potential of data loss for images. For text compression can be done without loss because you can find patterns that can be compressed into a table of common matching items.

However you can use different formats to keep quality of the image and reduce the size. So if you have a BMP converting it to GIF,PNG, or JPG will save room, but once you get to JPG you are at the smallest image format that I know of. Even going from hi-res PNG to JPG will produce noticeable loss of image quality. Using GZIP on a JPG file is nearly useless, and in some cases will cause your file size to get bigger.

There may be other solutions depending on what you are trying to do. In JavaME it not always about how to do (x), but rather how to give the illusion that (x) happened when in fact (y->z) is what was actually done. :)

-Shawn

jedusan
Offline
Joined: 2008-10-15
Points: 0

Thanks Shaw.
What must I do to compress the size of an image file to send from the mobile device to the server using J2ME?
This is my intention.
I I will use LWUIT.

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Why do you want to compress a image file that is already on a mobile device to send to the server? Are you having communication timeout issues or just want to save bandwidth/time sending the image to the server? If you are having timeout issues, then you may be trying to send the entire image buffer in one write() call. Instead send it in multiple 1-2k buffers may solve that issue. Or you may be running into the HTTP1.1 data chunking issue. In which case you may need to look for how to implement HTTP1.0 protocol over sockets, or look for the trick some phones use to shift from 1.1 back to 1.0 to avoid chunking.

For JavaME compression there are a couple decompression libraries, but the only compression library I found was by JCraft.
JCraft.com has a zlib library that has been said to be able to compile on JavaME.

However as I mentioned earlier, if the image is JPG, then you have hit the highest level of compression for images currently possible (to my knowledge). Using a gzip compression on it may in fact make it get larger. If the image is PNG, compression will not get it as small as conversion to JPG.

regards,
-Shawn

jedusan
Offline
Joined: 2008-10-15
Points: 0

I just want to save bandwidth/time sending the image to the server.
What should I do?

Thanks,
Eduardo