在BlackBerry下载并显示图像 [英] Download and show image on a BlackBerry

查看:101
本文介绍了在BlackBerry下载并显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开发涉及从URL中下载图片的URL,并显示在黑莓stimulator..Can谁能帮我在这方面???

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

推荐答案

这code'会连接指定的URL并返回位图对象

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;
     }

ü可以创建一个bimapfield和ASIGN此位图

U can create a bimapfield and asign this bitmap as

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

这篇关于在BlackBerry下载并显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆