1

我需要下载 jpeg 图像并将其显示在我的 midlet 中。但是当我尝试运行此代码时,屏幕上的图像已损坏。怎么了?

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) {

        }
}

谢谢

4

0 回答 0