Android显示网络图片Step1:
//浏览网络图片
public class WebImageViewActivity extends Activity implements OnItemClickListener
{
//String imageUrl = "http://i.pbase.com/o6/92/229792/1/80199697.uAs58yHk.50pxCross_of_the_Knights_Templar_svg.png";
public static String imageUrl = "";
Bitmap bmImg;
ImageView imView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.web_imageview_activity);
//imageUrl="http://www.iwapzone.com/templets/default/images/apc_bg.png";
imView = (ImageView) findViewById(R.id.imgview);
imView.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 is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onDestroy()
{
super.onDestroy();
Intent intent = new Intent(this, PlayFileService.class);
stopService(intent);
}
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
其中,returnBitMap(String url) 方法就是具体实现网络图片转换成bitmap。
Android显示网络图片Step2:
web_imageview_activity.xml
android:orientation="vertical" android:background="@android:color/transparent" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
Android显示网络图片Step3:
在你的AndroidManifest.xml文件的< /manifest>节点上面添加
< uses-permission android:name="Android.permission.INTERNET" />,这是由于Android有很多的权限限制,否则图片是不能在你的模拟器上显示的。
http://www.189works.com/article-102567-1.html
http://www.189works.com/article-2612-1.html
http://wenku.baidu.com/view/1ecca51c964bcf84b9d57b80.html