根据图片的url路径获得Bitmap对象

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

/**
 * 根据图片的url路径获得Bitmap对象
 * @param url
 * @return
 */
private Bitmap returnBitmap(String url) {
	URL fileUrl = null;
	Bitmap bitmap = null;

	try {
		fileUrl = new URL(url);
	} catch (MalformedURLException e) {
		e.printStackTrace();
	}

	try {
		HttpURLConnection conn = (HttpURLConnection) fileUrl
				.openConnection();
		conn.setDoInput(true);
		conn.connect();
		InputStream is = conn.getInputStream();
		bitmap = BitmapFactory.decodeStream(is);
		is.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return bitmap;

}

转载于:https://my.oschina.net/guoqiantong/blog/120788

你可能感兴趣的:(根据图片的url路径获得Bitmap对象)