JPEG Encoder for J2ME

4/3/2008

I've used the JPEG encoder at
http://koders.com/java/fidD639747F90884439A2FE45CF0C95E9B82D9473F8.aspx?s=net.sourceforge.processdash.ui.lib
which is actually written as a Java Application and ported it to J2ME. Here is the list of changes to the mentioned program :

ØSince j2me doesn't support BufferedOutputStream at this time, I used DataOutputStream instead.
ØIt seems that a call to Compress() method has missed. So the correct form is as follows :

ØSome of the methods of Math class ( most of all round() ) are not supported in J2ME. So these methods can be omitted without any special changes. I have omitted the round() method.
One of the most important changes is getting value of images. Since there is no PixelGrabber class in J2ME, using getRGB() method seems more satisfactory, so

is changed to

There are some other small changes. The whole JPEG Encoder can be downloaded here. Download JpegEncoder.java
 

To use this class, I have created a method as follows which saves an image to specified file (JSR 75 is needed).

This method saves an Image to result.jpg using JPEG Encoder.

I tested it and got suitable result. If there is any suggestion or bug report or anything else, i would be grateful if contact me : pooya.amini [at] gmail [dot] com