3

我正在使用 Blackberry JDE(9000 模拟器),我想知道是否可以显示来自网络的图像。

目前,我正在查看Bitmap.getBitmapResource用于显示黑莓应用程序本地图像的教程,但查看 API,我没有看到任何对提供 Web URL 的支持。

还有其他我可以查看的黑莓图像类吗?还是不支持此功能?

4

3 回答 3

4

You can download image using HTTPConnection and InputStream, create EncodedImage from stream and then display it.

See coderholic - Blackberry WebBitmapField

BTW, you can use IOUtilities.streamToBytes() method to read bytes from InputStream directly!

于 2009-09-14T14:47:06.713 回答
1

这是您的问题的代码示例:

    HttpConnection httpConn = null;
    InputStream inputStream = null;
    int ResponseCode = HttpConnection.HTTP_OK;
    byte[] ResponseData = null;

    try {
        httpConn = (HttpConnection) Connector.open(url, Connector.READ, true); 

        ResponseCode = httpConn.getResponseCode();
        if (ResponseCode == HttpConnection.HTTP_OK) {
            inputStream = httpConn.openInputStream();               
            ResponseData = IOUtilities.streamToBytes(inputStream);
        }
    }
    catch(IOException e){
        throw new IOException("HTTP response code: "
                + ResponseCode);
    }
    finally {
        try {
            inputStream.close();
            inputStream = null;
            httpConn.close();
            httpConn = null;
        }
        catch(Exception e){}
    }
    return ResponseData;
于 2011-12-11T19:44:24.217 回答
0

如果您想要完全执行此操作的代码(尽管这篇文章很旧,所以我猜您不再需要了)

这里

于 2011-08-20T06:23:29.193 回答