This version of www.jasonlam604.com is deprecated.
If you are not redirected to the new web site in 3 seconds, please click on the following link
http://www.jasonlam604.com/v2/index.php
 

 


J2ME HTTP GET Images
by Jason Lam s

The code to read an image from the server is as follows:

DataInputStream iStrm = conn.openDataInputStream();
byte imageData[];

// If size is known
if (length != -1) {
    imageData = new byte[length];

    // Read the Image data into an array
    iStrm.readFully(imageData);

// If size is NOT known
} else {
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
    int ch;
    while ((ch = iStrm.read()) != -1)
        bStrm.write(ch);
    imageData = bStrm.toByteArray();
    bStrm.close();
}

// Contains Image retrieved in an Image Object
image = Image.createImage(imageData, 0, imageData.length);

 

| Home | Tutorials | Tips / Hints | Books | Links |
| Resume | Portfolio | Services | Contact |

The contents of this webpage are copyright © 2003 - 2006
Jason Lam All Rights Reserved