×
Namespaces

Variants
Actions
(Difference between revisions)

Get Web Image in MIDlet

From Nokia Developer Wiki
Jump to: navigation, search
r60600 (Talk | contribs)
(Created page with "Category:Java MECategory:Series 40 MIDlet usually uses web image which can be get via <pre>private String url; private byte[] data; private int datalength; private Data...")
 
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix metadata)
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
[[Category:Java ME]][[Category:Series 40]]
+
[[Category:Java ME]][[Category:Series 40]][[Category:Networking]]
 +
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20110602
 +
|author= [[User:R60600]]
 +
}}
  
 
MIDlet usually uses web image which can be get via
 
MIDlet usually uses web image which can be get via
<pre>private String url;
+
<code java>private String url;
 
private byte[] data;
 
private byte[] data;
 
private int datalength;  
 
private int datalength;  
Line 16: Line 38:
 
if (datalength &gt; 0)  
 
if (datalength &gt; 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);
}</pre>
+
}</code>
 +
<!-- Translation --> [[zh-hans:网络图片资源处理]]

Revision as of 09:24, 26 September 2012

Article Metadata
Article
Created: r60600 (02 Jun 2011)
Last edited: hamishwillee (26 Sep 2012)

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);
}
9 page views in the last 30 days.
×