×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Bangalore
    Posts
    117

    How to fetch the Image from Server

    Hello Can anybody guide me for fetching Image from Server

    Regards
    Chandu

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    393
    Here's to get you going

    private Image downloadImage( String url) {
    ByteArrayOutStream baos = new ByteArrayOutStream();
    try {
    // Opening the connection
    HttpConnection conn = (HttpConnection)Connector.open(url);
    InputStream inputStream = conn.openInputStream();

    byte[] nextByte = new byte[1];
    //Reading the image byte by byte
    while((inputStream.read(nextByte, 0, 1)) != (-1)) {
    baos.write(nextByte[0]);
    }

    //Closing the connection
    conn.close();
    inputStream.close();
    } catch { System.out.println("Downloading image failed"); }

    return Image.createImage(baos.toByteArray(), 0, baos.size()); // Creating new image from the fetched byte array
    }

    Remember to make you HTTP connection in a separate thread and close the connections and streams in a finally block.

    [N]/Forum Nokia

Posting Permissions

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