I know how to display a JPEG picture in the JAR package using the following code:
But the real condition is that I have to display the JPEG picture got from internet such as "http://myserver/abc.jpg".Code:Image im = Image.createImage("/abc.jpg");
I can use HttpConnection to fectch the JPEG picture's data:
I can get the correct JPEG data which is contained in the byte array.I also can store it using RecordStoreCode: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 even find the store file in the emulator,it can be displayed correctly.Code:RecordStore rs = RecordStore.openRecordStore("rs.jpg",true); rs.addRecord(data, 0, len);
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
It throws an execption means wrong format.Code:Image im = Image.createImage(data,0,len-1);
I just want to know how I should do to retreive the image through Internet.

Reply With Quote

