【问题标题】:Download and show image on a BlackBerry在 BlackBerry 上下载并显示图像
【发布时间】:2010-11-30 04:35:13
【问题描述】:

我必须开发一个 url,其中涉及从 url 下载图像并在黑莓刺激器中显示..有人可以在这方面帮助我吗???

【问题讨论】:

标签: blackberry


【解决方案1】:

此代码将连接给定的 URL 并返回 Bitmap 对象

  public static Bitmap connectServerForImage(String url) {

      HttpConnection httpConnection = null;
      DataOutputStream httpDataOutput = null;
      InputStream httpInput = null;
      int rc;

      Bitmap bitmp = null;
      try {
       httpConnection = (HttpConnection) Connector.open(url);
       rc = httpConnection.getResponseCode();
       if (rc != HttpConnection.HTTP_OK) {
        throw new IOException("HTTP response code: " + rc);
       }
       httpInput = httpConnection.openInputStream();
       InputStream inp = httpInput;
       byte[] b = IOUtilities.streamToBytes(inp);
       EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
       return hai.getBitmap();

      } catch (Exception ex) {
       System.out.println("URL Bitmap Error........" + ex.getMessage());
      } finally {
       try {
        if (httpInput != null)
         httpInput.close();
        if (httpDataOutput != null)
         httpDataOutput.close();
        if (httpConnection != null)
         httpConnection.close();
       } catch (Exception e) {
        e.printStackTrace();

       }
      }
      return bitmp;
     }

你可以创建一个bimapfield并将这个位图指定为

BitmapField bmpFld1=new BitmapField(connectServerForImage(Url));

【讨论】:

  • 这是我必须扩展到ui应用程序类的代码吗??
  • 不需要..你可以分开保存。在屏幕中添加位图字段。
【解决方案2】:

用于base 64字符串解码

 try {
    mapaByte = Base64InputStream.decode(imagenB64);
    Bitmap mapa64 = Bitmap.createBitmapFromBytes(mapaByte, 0, -1, 1);
    mapa.setBitmap(mapa64);
     } 
 catch (Exception e) {}

【讨论】:

    猜你喜欢
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 2023-04-10
    • 2018-08-20
    • 1970-01-01
    • 2011-09-09
    相关资源
    最近更新 更多