j2me - How to create image in jpg format?

匆匆过客 提交于 2019-12-02 03:09:55

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1277886/j2me-how-to-create-image-in-jpg-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!