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

目前,我看到使用 Bitmap.getBitmapResource 的教程来显示黑莓应用程序本地的图像,但是看看API,我没有看到任何支持给web的支持URL。

我可以查看其他Blackberry图像类吗?或者这个功能是否不受支持?

有帮助吗?

解决方案

您可以使用 HTTPConnection <下载图像/ a>和 InputStream ,创建<流中的href =“http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/EncodedImage.html”rel =“nofollow noreferrer”> EncodedImage 然后显示它。

请参阅 coderholic - Blackberry WebBitmapField

顺便说一句,您可以使用 IOUtilities.streamToBytes()方法直接从InputStream读取字节!

其他提示

以下是您的问题的代码示例:

    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;

如果你想要完全做到这一点的代码(虽然这篇文章很旧,所以我猜你不再这样了)

此处

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top