从网站提取图像

问题描述:

如何从网站中提取图像并在网格或列表视图中显示?从网站提取图像

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


    } 

试试这个

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.setImageDrawable(d); 

显示您可以将一个ImageView的添加到列表中的每一行,并设置可绘制的可绘制。

如果你想分析整个网站,我更喜欢使用Jerico HTML Parser,它可以在Android上正常工作(试过),然后你可以搜索<img>元素来获取图像的URL。