当前位置: 代码迷 >> Android >> android中,网上的图,怎么在界面中显示
  详细解决方案

android中,网上的图,怎么在界面中显示

热度:57   发布时间:2016-05-01 22:01:13.0
android中,网上的图,如何在界面中显示,在线等
有一图,是网上的 http://0791.8ff.cn/upload/colorful/2012-01/201201310912572359384.jpg
现需:1 如何在界面中显示此图
  2 android手机上大 中 小分辩率,对于此图如何用大 中小 图呢
  3 如何把此图存到本地,再给界面用呢

thanks

------解决方案--------------------
public class Activity01 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView iv= (ImageView) findViewById(R.id.ImageView01);
iv.setImageBitmap(GetNetBitmap("http://0791.8ff.cn/upload/colorful/2012-01/201201310912572359384.jpg
"));
}
public Bitmap GetNetBitmap(String url)
{
URL imagUrl=null;
Bitmap bitMap=null;
try
{
imagUrl= new URL(url);
HttpURLConnection conn= (HttpURLConnection) imagUrl.openConnection();
//将得到的数据转换成InputStream;
InputStream is=conn.getInputStream();
//将InputStream转换成BitMap
bitMap = BitmapFactory.decodeStream(is);
is.close();

}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitMap;
}
}
记得开通访问网络的权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
别忘了给分
  相关解决方案