1
<description>
div class=&quot;field field-type-filefield field-field-book-review-image&quot;&gt;
    &lt;div class=&quot;field-items&quot;&gt;
            &lt;div class=&quot;field-item odd&quot;&gt;
                    &lt;img  class=&quot;imagefield imagefield-field_book_review_image&quot; width=&quot;500&quot; height=&quot;741&quot; alt=&quot;&quot; src=&quot;**http://sampada.net/files/good%20earth.JPG?1327387980**&quot; /&gt;        &

</description>
4

3 回答 3

1

你最好使用 DOM 而不是 SAX。只需遍历所有名为“img”的元素,获取“src”属性,构建一个 URL 并触发一个 AsyncTask 来下载流。

于 2012-10-30T09:40:58.400 回答
0

如果你只想要一张图片,我会用这个:

static final String image_URL = "http://sampada.net/files/good%20earth.JPG?1327387980";

//in the oncreate

ImageView bmImage = (ImageView)findViewById(R.id.<<your image id from the xml>>);
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
Bitmap bm = LoadImage(image_URL, bmOptions);
bmImage.setImageBitmap(bm);
//under the oncreate

private Bitmap LoadImage(String URL, BitmapFactory.Options options)
{       
    Bitmap bitmap = null;
    InputStream in = null;       
    try {
       in = OpenHttpConnection(URL);
       bitmap = BitmapFactory.decodeStream(in, null, options);
       in.close();
    } catch (IOException e1) {
    }
    return bitmap;               
}

private InputStream OpenHttpConnection(String strURL) throws IOException{
    InputStream inputStream = null;
    URL url = new URL(strURL);
    URLConnection conn = url.openConnection();

    try{
        HttpURLConnection httpConn = (HttpURLConnection)conn;
        httpConn.setRequestMethod("GET");
        httpConn.connect();

        if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
            inputStream = httpConn.getInputStream();
        }
    }
    catch (Exception ex)
    {
    }
    return inputStream;
}

希望这可以帮助你。

于 2012-10-30T08:22:17.973 回答
0

尝试以下开源库:

http://htmlcleaner.sourceforge.net/

以下是更多的 HTML 解析器:

http://java-source.net/open-source/html-parsers

于 2012-10-30T07:57:50.173 回答