Namespaces
Variants
Actions
(Difference between revisions)

Get Web Image in MIDlet

Jump to: navigation, search
m (Hamishwillee - Fix code blocks)
m (Hamishwillee - Fix typo)
Line 36: Line 36:
 
if (datalength > 0)  
 
if (datalength > 0)  
 
image = Image.createImage(data, 0, datalength);  
 
image = Image.createImage(data, 0, datalength);  
}catch (java.io.IOException x){}</pre>
+
}catch (java.io.IOException x){}
 +
</code>
 
If the image object is created successfully,it can be displayed by usual way.
 
If the image object is created successfully,it can be displayed by usual way.
 
Such like in Canvas
 
Such like in Canvas
<pre>protected void paint(Graphics g)
+
<code java>protected void paint(Graphics g)
 
{
 
{
 
g.drawImage(image,0, 0, Graphics.LEFT|Graphics.TOP);
 
g.drawImage(image,0, 0, Graphics.LEFT|Graphics.TOP);
 
}</code>
 
}</code>

Revision as of 09:06, 12 December 2011

Article Metadata

Article
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)Connector.open(url);
datalength = (int)hc.getLength();
dis = hc.openDataInputStream();
data = new byte[datalength];
dis.readFully(data);
if (datalength &gt; 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);
}
56 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved