Saturday, March 05, 2005

JPG image support in MIDP. How to detect it in J2ME

(Soporte para imagenes JPG en MIDP. Como detectarlo en J2ME)

At my last project we have to show certain downloaded images in a mobile phone using J2ME. The images are in jpeg format, and we pass them throughout an adapter for preprocess the width and the format.

As they are camera images, if we send to the phone in png format, they has more or less 15 KB, but if we send them in jpg, only 3 or 4 KB are needed, but...

As MIDP standard says:

"...Implementations are required to support images stored in the PNG format, as specified by the PNG (Portable Network Graphics) Specification, Version 1.0. All conforming MIDP implementations are also conformant to the minimum set of requirements given by the PNG Specification."

Well, to manage those problem we execute the following routine when the application loads.

boolean support_JPG = false;
try{
  Image img = Image.createImage("/res/p.jpg");
  support_JPG= true ;
  img = null;
  System.out.println("JPG support is true");
catch(Exception e){
    System.out.println("JPG support is false");
}

They idea is put a small pixel jpeg file(160 bytes) in the resources and try to load it, and if no exception is thrown, we suppose that the jpg format is supported by the phone, and we store this value in a boolean variable called support_JPG. Another thing thath you can do, is call this routine only the first time that the app runs in the phone and store this value using RMS(Recommended).


Permalink: JPG image support in MIDP. How to detect it in J2ME 

0 Comments:

Post a Comment

<< Home