开发者

Trouble with download jpeg image

开发者 https://www.devze.com 2023-03-19 23:14 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消