I know how to display a JPEG picture in the JAR package using the following code:
Code:
Image im = Image.createImage("/abc.jpg");
But the real condition is that I have to display the JPEG picture got from internet such as "http://myserver/abc.jpg".
I can use HttpConnection to fectch the JPEG picture's data:
Code:
HttpConnection httpConn = (HttpConnection)Connector.open(url);
            httpConn.setRequestProperty("Authorization", "Basic "+Base64Converter.encode(userPwd));
            InputStream is = httpConn.openInputStream();
int len = (int)httpConn.getLength();
             if (len > 0) {
                 int actual = 0;
                 int bytesread = 0 ;
                 byte[] data = new byte[len];
                 while ((bytesread != len) && (actual != -1)) {
                    actual = is.read(data, bytesread, len - bytesread);
                    bytesread += actual;
                 }
             }
I can get the correct JPEG data which is contained in the byte array.I also can store it using RecordStore
Code:
RecordStore rs = RecordStore.openRecordStore("rs.jpg",true);
rs.addRecord(data, 0, len);
I can even find the store file in the emulator,it can be displayed correctly.
So I draw a conclusion that S60's midp implementation includes JPEG codec.
But unfortunately,I cannot use those data to create an Image using the following codes
Code:
Image im = Image.createImage(data,0,len-1);
It throws an execption means wrong format.
I just want to know how I should do to retreive the image through Internet.