×
Namespaces

Variants
Actions
Revision as of 18:00, 2 June 2011 by r60600 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Get Web Image in MIDlet

From Nokia Developer Wiki
Jump to: navigation, search


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)Connector.open(url);
datalength = (int)hc.getLength();
dis = hc.openDataInputStream();
data = new byte[datalength];
dis.readFully(data);
if (datalength > 0) 
image = Image.createImage(data, 0, datalength); 
}catch (java.io.IOException 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);
}
27 page views in the last 30 days.
×