Skip to content

Instantly share code, notes, and snippets.

@davidllorca
Created September 16, 2015 10:51
Show Gist options
  • Save davidllorca/28bd2e368f37534f4c3f to your computer and use it in GitHub Desktop.
Save davidllorca/28bd2e368f37534f4c3f to your computer and use it in GitHub Desktop.
Download image with HttpURLConnection
/**
* Get image from url.
*
* @param src image url.
* @return Bitmap object.
*/
private Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap mBitmap = BitmapFactory.decodeStream(input);
return mBitmap;
} catch (IOException e) {
// Log exception
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment