获取网络图片的工具类

public class GetBitmapUtil {

	public Bitmap getBitmapByUrl(String url){
		Bitmap bitmap = null;
		try {
			URL url2=new URL(url);
			HttpURLConnection httpURLConnection=(HttpURLConnection) url2.openConnection();
		    httpURLConnection.setReadTimeout(3000);
		    int code=httpURLConnection.getResponseCode();
		    if(code==200){
		    	bitmap=BitmapFactory.decodeStream(httpURLConnection.getInputStream());
		    }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bitmap;
	}
}



你可能感兴趣的:(android,网络,图片)