Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Introduction to Fresco image loading library for Android Application

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.26k
    Comment on it

    Hello Nerds, Are you still facing lazy image loading or OutOfMemoryException using Universal image loader, Picasso, Glide or any other library? If Yes, then this tutorial will be very helpful for you. Fresco image loading library provides quick loading of images over any other library. It provides lots of customization features, like progressBarImage, placeholderImage, failureImage, retryImage, backgroundImage, roundAsCircle, watermark and much more. Some of the features are described below.

    Features of Fresco Image Loading library:

    1. For storing images, Asynchronous shared heap is used instead of Java heap. This will leave lots of free memory for other applications and reduces the risk of OutofMemory exception.
    2. Not only to the center, but images can be cropped at any point.
    3. Images can be resized.
    4. JPEG images can be streamed, just like the web browser.  
    5. Reduces garbage collection.
    6. Operations are in a parallel manner.

    Steps to implement this library in your android application

    Step1: Add dependency on a build.gradle file

    // If your application supports Ice Cream Sandwich Android OS version(API level 14)
      compile 'com.facebook.fresco:animated-base-support:0.14.1'
    
      // For animated GIF images support
      compile 'com.facebook.fresco:animated-gif:0.14.1'
    
      // For WebP support, including animated WebP
      compile 'com.facebook.fresco:animated-webp:0.14.1'
      compile 'com.facebook.fresco:webpsupport:0.14.1'
    
      // For WebP support, without animations
      compile 'com.facebook.fresco:webpsupport:0.14.1'
    
      // For basic application support
      compile 'com.facebook.fresco:fresco:0.14.1'

    Step2: Create an application class and initialize the library in it.

           Fresco.initialize(this);

    Note: If not creating application class and need to use it directly in a single class, in that case just initialize the above code before setContentView method of that activity.

    Step3: For supporting android XML tag

    <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/sdvImage"
                android:layout_width="300dp"
                android:layout_height="300dp"
                android:visibility="gone"
                android:layout_gravity="center"
                fresco:placeholderImage="@drawable/placeholder"
                fresco:fadeDuration="300"
                fresco:actualImageScaleType="focusCrop"
                fresco:placeholderImageScaleType="fitCenter"
                fresco:failureImage="@drawable/failed"
                fresco:failureImageScaleType="centerInside"
                fresco:retryImage="@drawable/retry"
                fresco:retryImageScaleType="centerCrop"
                fresco:progressBarImage="@drawable/progress_bar"
                fresco:progressBarImageScaleType="centerInside"
                fresco:progressBarAutoRotateInterval="1000"
                fresco:backgroundImage="@android:color/white"
    	    fresco:overlayImage="@drawable/watermark"
                fresco:pressedStateOverlayImage="@color/red"
                fresco:roundAsCircle="true"
                fresco:roundedCornerRadius="1dp"
                fresco:roundTopLeft="true"
                fresco:roundTopRight="false"
                fresco:roundBottomLeft="false"
                fresco:roundBottomRight="true"
                fresco:roundingBorderWidth="2dp"
                fresco:roundingBorderColor="@color/border" />

    Step4: Initialize SimpleDraweeView and set image path on it.

    SimpleDraweeView sdvImage = (SimpleDraweeView) findViewById(R.id.sdvImage);
    
    	Uri imageUri = Uri.parse(imageURI);
            sdvImage.setImageURI(imageUri);

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: