下载jpeg图片时出现问题

时间:2011-07-11 14:21:56

标签: image java-me midlet httpconnection

我需要下载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) {

        }
}

由于

0 个答案:

没有答案