Get Web Image in MIDlet
hamishwillee
(Talk | contribs) m (Hamishwillee - Fix code blocks) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot update - Fix metadata) |
||
| (2 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Java ME]][[Category:Series 40]][[Category:Networking]] | [[Category:Java ME]][[Category:Series 40]][[Category:Networking]] | ||
| − | {{ArticleMetaData | + | {{ArticleMetaData <!-- v1.2 --> |
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] --> | |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]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| Line 7: | Line 7: | ||
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| − | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> |
| − | |signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | + | |signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> |
| − | |capabilities=<!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> |
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| − | + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | |
| − | |language=<!-- Language category code for non-English topics - e.g. Lang-Chinese --> | + | |translated-by= <!-- [[User:XXXX]] --> |
| − | |review-by=<!-- After re-review: [[User:username]] --> | + | |translated-from-title= <!-- Title only --> |
| − | |review-timestamp=<!-- After re-review: YYYYMMDD --> | + | |translated-from-id= <!-- Id of translated revision --> |
| − | |update-by=<!-- After significant update: [[User:username]]--> | + | |review-by= <!-- After re-review: [[User:username]] --> |
| − | |update-timestamp=<!-- After significant update: YYYYMMDD --> | + | |review-timestamp= <!-- After re-review: YYYYMMDD --> |
| − | |creationdate=20110602 | + | |update-by= <!-- After significant update: [[User:username]]--> |
| − | |author=[[User:R60600]] | + | |update-timestamp= <!-- After significant update: YYYYMMDD --> |
| + | |creationdate= 20110602 | ||
| + | |author= [[User:R60600]] | ||
}} | }} | ||
| Line 36: | Line 38: | ||
if (datalength > 0) | if (datalength > 0) | ||
image = Image.createImage(data, 0, datalength); | image = Image.createImage(data, 0, datalength); | ||
| − | }catch (java.io.IOException x){}</ | + | }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 | ||
| − | < | + | <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> | ||
| + | <!-- Translation --> [[zh-hans:网络图片资源处理]] | ||
Revision as of 09:24, 26 September 2012
Article Metadata
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

