Android Fresco Image Library – Load Images Using Fresco

 

Fresco Image Library :

Loading images sometimes turn up to be a difficult task if there are more to be loaded the new fresco image library makes your work much simpler.Using this library you can load images from server as well as local resources.It also uses a cache to avoid unnecessary wastage of CPU resource.

Also this image library to make the image appear faster then before making a low resolution image load before we get the high resolution.You can see this feature in social networking apps like facebook, Instagram and many more where there is a high usage of images to be loaded.

Streaming is one more advantage using this Fresco Image Library as it updates display when more data arrives from the source, most of the image library’s are not having streaming option.

Even loading animated images turns out to be much more flexible as fresco handles loading of every frame and also proper disposing of them after the use so as to maintain stability of memory.

Fresco Image Library is from facebook, and any help regarding the usage, query you can visit official website Fresco to know more.

 

Lets start loading a image using this Fresco Image Library.

 

activity_main

Starting with layout design add a image view also called as DraweeView as

 

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/compLogo"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/compLogo"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

 

MainActivity

Then start initializing Fresco Image Library in the activity where we want to load the image

Fresco.initialize(this);

make sure you initialize the library just before

setContentView(R.layout.activity_main);

because we are using the DraweeView in layout file which is to be initialized before.

 

Initialize SimpleDraweeView

SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.compLogo);

 

add your image url

Uri imageUri = Uri.parse("Image Url Here");

 

then set the image to view as

draweeView.setImageURI(imageUri);

 

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Fresco.initialize(this); // Initialize

        setContentView(R.layout.activity_main);

        Uri imageUri = Uri.parse("Image Url Here");
        SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.compLogo);
        draweeView.setImageURI(imageUri);

    }
}

If you like this tutorial on Fresco Image Library Share and like this tutorial for more interesting updates. If you have any query’s do let us know in comment section below regarding any query’s.

 

Show Buttons
Hide Buttons
Read previous post:
Android Custom ProgressBar || Material ProgressBar

  Android Custom ProgressBar : Custom ProgressBar, Android Progressbar is shown when there is a background task running and to...

Close