Blackberry Listfield与实时图像

时间:2011-04-01 14:00:43

标签: image blackberry listfield

我想在列表字段的所有行中显示带有实时图像的列表字段

1 个答案:

答案 0 :(得分:1)

结帐this

还使用以下代码显示实时图像:

public static String getImageFromUrl(String url) {
            //Image img = null;
            String imageData = null;
            try
            {            
              imageData = getDataFromUrl(url);
              //img = Image.createImage(imageData.getBytes(), 0,imageData.length() );          
            }
            catch(Exception e1) {
                e1.printStackTrace();
            }

            return imageData;
        }

        public static String getDataFromUrl(String url) 
              throws IOException {

            StringBuffer b = new StringBuffer();
            InputStream is = null;
            HttpConnection c = null;

            long len = 0 ;
            int ch = 0;

            ConnectionFactory connFact = new ConnectionFactory();
              ConnectionDescriptor connDesc;
              connDesc = connFact.getConnection(url);

              if (connDesc != null)
              {
                  //HttpConnection httpConn;
                  c = (HttpConnection)connDesc.getConnection();
              }

           // c = (HttpConnection)Connector.open(url);
            is = c.openInputStream();
            len = c.getLength();
            if( len != -1) {
                // Read exactly Content-Length bytes
                for(int i =0 ; i < len ; i++ )
                    if((ch = is.read()) != -1) {
                    b.append((char) ch);
                    }
            } else {
                //Read until the connection is closed.
                while ((ch = is.read()) != -1) {
                    len = is.available() ;
                    b.append((char)ch);
                }
            }

            is.close();
            c.close();
            return b.toString();
        }  

希望这会对你有所帮助。