Image.createImage problem in J2ME

I tried this on J2ME

try {
    Image immutableThumb = Image.createImage( temp, 0, temp.length);
} catch (Exception ex) {
    System.out.println(ex);
}

      

I hit this error: java.lang.IllegalArgumentException:

How to solve this?

0


source to share


4 answers


Image.createImage () will throw an IllegalArgumentException if the first argument is not formatted correctly or otherwise cannot be decoded. (I am assuming temp is byte []).

http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Image.html#createImage(byte [],%20int,%20int)



(This URL refuses to become a hyperlink for some reason (?))

+1


source


It's hard to tell without any details or more surrounding code, but my initial suspicion is that the file you are trying to download is in a format not supported by the device.



+1


source


Let's take a look at the docs: IllegalArgumentException thrown

if ImageData is not formatted correctly or otherwise cannot be decoded

Thus, a possible cause could be either an unsupported image format or truncated data. Remember that you must pass the entire file to this method, including all headers. If you have doubts about the format, you are better off choosing PNG , it should be supported anyway.

+1


source


I had the same problem with my MIDLET and the problem in my case was the HTTP header that comes with the JPEG image I was reading from the InputStream socket. And I solved it by finding the SOI JPEG marker that is identified by two bytes: FFD8

in my byte array. Then when I find a location FFD8

in my byte array, I strip off the initial bytes that represent the HTTP header, and then I could throw an createImage()

Exception without an exception ...

You must check if this is the case with you. Just check (temp[0] == 0xFF && temp[1] == 0xD8)

if it's true , and if it isn't, trim the beginning temp

to remove the HTTP header or some other junk ...

PS I am assuming you are reading a JPEG image, if not, find the corresponding header in the array temp

.

Also if that doesn't help and you are reading a JPEG image make sure the array starts with FFD8

and ends with FFD9

(which is an EOI marker). And if it doesn't end up with the EOI just cutting off the end as I explained for SOI ...

PPS And if you find that the data is temp

valid, your platform cannot decode JPEG images or the image temp

is large for a JPEG decoder.

0


source







All Articles