80,351
社区成员
发帖
与我相关
我的任务
分享
ImageView imgView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgView = (ImageView) findViewById(R.id.imgView);
imgView.setImageBitmap(getBitMap("http://XXXX.com/your.jpg"));
}
public Bitmap getBitMap(String imgUrl) {
URL urlImg = null;
Bitmap bmp = null;
try {
urlImg = new URL(imgUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) urlImg
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmp = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
}
return bmp;
}