Image.createImage problem in J2ME
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.
source to share
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.
source to share