×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    7

    I want to know how to retreive a JPEG picture from internet

    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.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Rotterdam, Holland
    Posts
    118
    Well, it seems to not accept a JPG data stream as input. which would mean it simply doesnt support JPG images by default. As far as i know, there's no JPG support in MIDP 1.0/2.0, but it's been a while since i read through the specs. Making your custom JPG decoder is doable though, and i'm sure there are (java) code snippets around on the net for this.

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    I think:
    Code:
    Image im = Image.createImage(data,0,len-1);
    should read:
    Code:
    Image im = Image.createImage(data,0,len);
    If that doesn't help, make sure you are actually getting the data you expect - it is the right length and the right byte-values.

    Graham.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×