Zhambulable
Zhambulable

Reputation: 1093

How to convert url to image to Image?

I get url to my Image, and want it make Image; I want use this methods

 URL url = new URL("http://www.digitalphotoartistry.com/rose1.jpg");
java.awt.Image image = java.awt.Toolkit.getDefaultToolkit().getDefaultToolkit().createImage(url); 

or

URL url = new URL("http://www.digitalphotoartistry.com/rose1.jpg");
Image image = ImageIO.read(url);  

but Android Studio can't find ImageIO and java.awt.Toolkit. How can I add them?

Upvotes: 0

Views: 3189

Answers (1)

Aakash
Aakash

Reputation: 5251

You can get Bitmap from url and then you can use that bitmap further to set image of an ImageView.

URL url = new URL("http://....");
Bitmap  image=BitmapFactory.decodeStream(url.openConnection().getInputStream());

Upvotes: 2

Related Questions