2011-04-28 5 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

以下のコードは、画像を取得するのに役立ちます。あなたが画像のURLを渡すならば。

 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の

 imageView.setImageDrawable(d); 

に表示し、描画可能に設定することができます描画可能に返されます。

0

ウェブサイト全体を解析する場合は、Jerico HTML Parserを使用することをお勧めします。これはAndroid(試してみた)でうまくいき、画像URLを取得するために<img>要素を検索できます。