You can use the Picasso
.
Picasso
is a very popular and used library in Android development that solves all the problem of loading and processing images for you and also simplifies the display of third party images (such as URL’s). The Picasso
makes from the requisition (HTTP
) up to the cache of this image for future use.
1) Add the Picasso
in his build.gradle
and Sincronize your project:
compile 'com.squareup.picasso:picasso:2.5.2'
2) If not, add the internet permission to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET"/>
3) Create a ImageView
any to display your image:
<ImageView
android:id="@+id/suaImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
4) Now, on your Activity
(or Fragment
or any other place that wants to display an image) just reference your ImageView
and tell the Picasso
upload your URL:
ImageView suaImageView = (ImageView) findViewById(R.id.suaImageView);
Picasso.with(this)
.load("http://www.dominio.com.br/imagem.jpg")
.into(suaImageView);
You also have the possibility to manipulate your image, for example:
Picasso.with(context)
.load(url)
//Definindo uma resolução para sua imagem
.resize(50, 50)
//Definindo um Scale Type para a sua imagem
.centerCrop()
.into(imageView)
Links:
Official page of Picasso
: http://square.github.io/picasso/
Page of GitHub
of Picasso
: https://github.com/square/picasso
Thanks for the answer, it was easier than it looked. I used: Bitmap bitmap = Bitmapfactory.decodeStream(Conn.getInputStream(); to get to Bitmap and then used: imageView.setImageBitmap(bitmap);
– Micael Costa