views:

1337

answers:

3

My j2me application must take a photo, edit it a little and save it somewhere (or send to server). Camera return me bytes of an image in jpg format, but after I create an Image object from it (using Image.createImage()), I could not pack it back to jpg.

Is there any jpeg encoders for j2me?
I found one written in j2se, but it uses j2se-specific classes.

A: 

It is purely implementation dependent, some devices allow you to create an Image object using a jpg file while others don't. However Sun's spec says that devices must support png, however others are at the discretion of the OEM manufacturers

Ram
Most recent devices supports _opening_ (decode) of jpg-image. But I need to save my custom image to jpeg. Maybe there is some vendor-specific API, which can _save_ (encode) in jpeg format?
Pavel Alexeev
+2  A: 

This can be done! Even without any proprietary APIs or libraries. This can be achieved if your phone supports JSR 234 and has the ability to process JPEG files through it. You do this:

//Create MediaProcessor for raw Image
MediaProcessor mediaProc = GlobalManager.createMediaProcessor("image/raw");
//Get control over the format
ImageFormatControl formatControl = (ImageFormatControl)
        mediaProc.getControl("javax.microedition.amms.control.ImageFormatControl");
//Set necessary format
formatControl.setFormat("image/jpeg");

Then you set input Image, output stream and start the media processor. Voila! You have saved your image in JPEG.

Malcolm
A: 

By the way, since JSR 234 is not supporting on many devices, I take Sun's JIMI image library and port JPEG-encoding part to j2me. It works fine and doesn't use too much memory.

Pavel Alexeev