Tushar
Tushar

Reputation: 5935

Download and show image on a BlackBerry

I have to develop a url which involves downloading image from url and show in blackberry stimulator..Can anyone help me in this regard???

Upvotes: 2

Views: 3011

Answers (2)

user1649008
user1649008

Reputation: 11

For base 64 string decoding

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

Upvotes: 1

Razebond
Razebond

Reputation: 51

This code 'll connect the given URL and returns Bitmap object

  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 can create a bimapfield and asign this bitmap as

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

Upvotes: 3

Related Questions