现在的位置: 首页 > 综合 > 正文

通用代码库之网络

2018年05月01日 ⁄ 综合 ⁄ 共 407字 ⁄ 字号 评论关闭
/**
	 * 获取网络图片
	 * @param path
	 * @return
	 * @throws Exception
	 */
	public static Bitmap getImage(String path) throws Exception
	{
		
		URL url = new URL(path);
		HttpURLConnection conn = (HttpURLConnection)url.openConnection();
		conn.setRequestMethod("GET");
		conn.setConnectTimeout(5000);
		conn.connect();
		if(conn.getResponseCode()==200)
		{
			InputStream  inStream = conn.getInputStream();
			Bitmap bitmap = BitmapFactory.decodeStream(inStream);
			return bitmap;
		}
		return null;
	}

抱歉!评论已关闭.