×
Namespaces

Variants
Actions
Revision as of 14:20, 25 July 2013 by hamishwillee (Talk | contribs)

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

网络图片资源处理

From Nokia Developer Wiki
Jump to: navigation, search
WP Metro Icon Chinese.png
Article Metadata

文章
翻译:
r60600
最后由 hamishwillee 在 25 Jul 2013 编辑

编程中往往不仅需要处理本地的图片资源,还要处理网络中获取的图片数据,一般这样处理:

private String url;
private byte[] data;
private int datalength;
private DataInputStream dis;
private HttpConnection hc;
 
url = "http://xx/xx.gif" /* 或者"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){}

只要Image对象创建成功,就可以象显示普通Image对象那样显示出来。
例如在Canvas中显示:

protected void paint(Graphics g)
{
g.drawImage(image,0, 0, Graphics.LEFT|Graphics.TOP);
}


相关链接

This page was last modified on 25 July 2013, at 14:20.
216 page views in the last 30 days.
×