首页 > 代码库 > 获取网络图片的工具类

获取网络图片的工具类

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;
	}
}



获取网络图片的工具类