直接获取网络图片,通过转换成java的inputstream流处理成了bitmap予imageView可用。
[code src="java"]package com.hgx.test;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app .Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
public class ActivityMain extends Activity {
/** Called when the activity is first created. */
String imageUrl = "http://t0.gstatic.com/images?q=tbn:ANd9GcSebJw_gfWnVBgc3yzzu6xIxr0aHQ9vklYAOdfANCJ5IoAbe7BnaQ";
Bitmap bmImg;
ImageView imageView;
Button button1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView) findViewById(R.id.ImageView01);
imageView.setImageBitmap(returnBitMap(imageUrl));
}
public Bitmap returnBitMap(String url) {
URL myFileUrl = null;
Bitmap bitmap = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream inputstream = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(inputstream );
inputstream .close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
} [/code]