<description>
div class="field field-type-filefield field-field-book-review-image">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_book_review_image" width="500" height="741" alt="" src="**http://sampada.net/files/good%20earth.JPG?1327387980**" /> &
</description>
问问题
900 次
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
于 2012-10-30T07:57:50.173 回答