How to save an edited Image object as a JPG or TIFF file in J2ME?

Posted on 2009-12-17
Last Modified: 2013-11-24
Hello Experts!

I have a J2ME program that creates an Image object, adds some text to the Image saves the image to the cellphone disk as a JPG or TIFF file.

The only thing I haven't been able to do is to code the Image Object as a JPG or TIFF file.

Anybody knows how to do that? I'll be very greatful for your help.
Image img =Image.createImage(100,100);
Graphics graph = img.getGraphics();
graph.drawString("Hello World!", 0, 0, 0);
Image finalImg = Image.createImage(img);

SaveToJPG(finalImg); // I'm looking for THIS function!!

Open in new window

Question by:Dermofit
    LVL 14

    Expert Comment


    Which version of MIDP are you using?

    < 2.0:

    I can create an Image from an array of bytes. Can I do the reverse and get an array of bytes from an Image?

        Unfortunately, no. There's no API available for extracting anything more than the image's width, height, an instance of javax.microedition.lcdui.Graphics and mutability.

        With the MIDP 2.0 you can get the raw bytes from an instance of javax.microedition.lcdui.Image through the getRGB() API.


    For 2.0 see:

           getRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height)
              Obtains ARGB pixel data from the specified region of this image and stores it in the provided array of integers.

    LVL 14

    Accepted Solution

    You would then need to encode those bytes into JPG format.
    Check this link for more info on how to do that.

    Author Comment

    thanks for your help, but I need something more especific how to do this, jb1dev in the first answer you tell me that get a RGB but i don´t know what I need to do whit this array of int RGB, maybe I need a outputstream whit this or what? if you know please tell me

    P.S.: the link of the second answare doesn't work

    For more information the aplication is in MIDP 2.0


    Author Comment

    if anybody want to know how to do this, i found the answer in this page,

    this is a class that you can do the encode a Image to jpg file, and is for Java Me.

    Author Comment

    thank you so much jb1dev and sorry for the late answer.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now