2011-04-28 140 views

回答

2
Bitmap bmImg; 
    void downloadfile(String fileurl,ImageView img) 
    { 
     URL myfileurl =null; 
     try 
     { 
      myfileurl= new URL(fileurl); 

     } 
     catch (MalformedURLException e) 
     { 

      e.printStackTrace(); 
     } 

     try 
     { 
      HttpURLConnection conn= (HttpURLConnection)myfileurl.openConnection(); 
      conn.setDoInput(true); 
      conn.connect(); 
      int length = conn.getContentLength(); 
      int[] bitmapData =new int[length]; 
      byte[] bitmapData2 =new byte[length]; 
      InputStream is = conn.getInputStream(); 
      BitmapFactory.Options options = new BitmapFactory.Options(); 
      options.inSampleSize = 
      bmImg = BitmapFactory.decodeStream(is,null,options); 

      img.setImageBitmap(bmImg); 

      //dialog.dismiss(); 
      } 
     catch(IOException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
//   Toast.makeText(PhotoRating.this, "Connection Problem. Try Again.", Toast.LENGTH_SHORT).show(); 
     } 


    } 

試試這個

0

url解釋了有關使用異步任務,並在列表視圖中顯示被下載的圖像從遠程服務器下載圖像。

0

下面的代碼可以幫助你獲取圖像。如果你傳遞圖像的網址。

 public Drawable loadImageFromWebOperations(String url) 
{ 

    try 
    { 

     DefaultHttpClient client = new DefaultHttpClient(); 
     HttpGet httpGetRequest = new HttpGet(url); 
     HttpResponse response = client.execute(httpGetRequest); 
     InputStream is = response.getEntity().getContent(); 


     Drawable d = Drawable.createFromStream(is, "src name"); 

     return d; 

    } catch (Exception e) { 

     System.out.println("Exc="+e); 

     return null; 

    } 

} 

該代碼將返回您可以在ImageView的

 imageView.setImageDrawable(d); 

顯示您可以將一個ImageView的添加到列表中的每一行,並設置可繪製的可繪製。

0

如果你想分析整個網站,我更喜歡使用Jerico HTML Parser,它可以在Android上正常工作(試過),然後你可以搜索<img>元素來獲取圖像的URL。