簡體   English   中英

在BlackBerry上下載並顯示圖像

[英]Download and show image on a BlackBerry

我必須開發一個URL,其中涉及從URL下載圖像並顯示在Blackberry刺激器中。在這方面有人可以幫助我嗎?

此代碼將連接給定的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;
     }

U可以創建一個bimapfield並將該位圖分配為

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

對於base 64字符串解碼

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM