Trouble with download jpeg image
I need to download开发者_运维问答 jpeg image and show it in my midlet. But when I try to run this code, image on screen is broken. What is wrong?
public void startApp() {
HttpConnection conn = null;
InputStream is = null;
try {
conn = (HttpConnection) Connector.open("http://av.li.ru/227/2374227_8677578.jpg", Connector.READ, false);
conn.setRequestMethod( HttpConnection.GET);
int rc = conn.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new Exception("ResponseCode = " + rc);
}
is = conn.openDataInputStream();
byte []b = new byte[(int) conn.getLength()];
is.read(b);
Image img = Image.createImage(b, 0, b.length);
Form f = new Form("test");
f.append(img);
Display.getDisplay(this).setCurrent(f);
} catch (Exception e) {
}
}
Thanks
精彩评论