• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

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

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

  • 3
  • 2
1 Solution

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.

You would then need to encode those bytes into JPG format.
Check this link for more info on how to do that.
DermofitAuthor Commented:
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

DermofitAuthor Commented:
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.
DermofitAuthor Commented:
thank you so much jb1dev and sorry for the late answer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now