• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • 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

0
Dermofit
Asked:
Dermofit
  • 3
  • 2
1 Solution
 
jb1devCommented:

Which version of MIDP are you using?

< 2.0:

http://bellsouthpwp.net/m/c/mcpierce/javamefaq.html

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:

http://java.sun.com/javame/reference/apis/jsr118/

       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.

0
 
jb1devCommented:
You would then need to encode those bytes into JPG format.
Check this link for more info on how to do that.
http://ce.sharif.edu/~p_amini/j2me/JPEG_Encoder
0
 
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

thanks.    
0
 
DermofitAuthor Commented:
if anybody want to know how to do this, i found the answer in this page,

http://ce.sharif.edu/~p_amini/j2me/JPEG_Encoder

this is a class that you can do the encode a Image to jpg file, and is for Java Me.
0
 
DermofitAuthor Commented:
thank you so much jb1dev and sorry for the late answer.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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