Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 06:06, 12 December 2011 by hamishwillee (Talk | contribs)

Get Web Image in MIDlet

From Wiki
Jump to: navigation, search
Article Metadata
Created: r60600 (02 Jun 2011)
Last edited: hamishwillee (12 Dec 2011)

MIDlet usually uses web image which can be get via

private String url;
private byte[] data;
private int datalength;
private DataInputStream dis;
private HttpConnection hc;
url = "http://xx/xx.gif" /* or "http://xx/xx.jpg" */
try {
hc = (HttpConnection);
datalength = (int)hc.getLength();
dis = hc.openDataInputStream();
data = new byte[datalength];
if (datalength > 0)
image = Image.createImage(data, 0, datalength);
}catch ( x){}

If the image object is created successfully,it can be displayed by usual way. Such like in Canvas

protected void paint(Graphics g)
g.drawImage(image,0, 0, Graphics.LEFT|Graphics.TOP);
7 page views in the last 30 days.