I am making an app that when a button is clicked, it will grab an image from a URL or server and display it.
EXAMPLE
开发者_开发问答App1
Button1 = clicked
Then Image from server or URL will be displayed on screen in app.
The above answer seems correct.
Just on the other note, do all this operation in another thread than the UI Thread.
And have an ImageView
at handy in your layout so that when you have the image in bitmap, you can set that bitmap into the ImageView so that the user can see it.
Since the image can be quite large in size, if downloaded in UI Thread, it'll cause your app to freeze.
Just reformatting the above answer over here:
try {
Bitmap bitmap = BitmapFactory.decodeStream(
(InputStream)new URL("http://abc.com/image.jpg").getContent());
}catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
精彩评论