How to Load Images From URL Using Fresco in Android Kotlin

In this article, we will learn how to Load Images from URL in Android Studio using Fresco in Kotlin. At the end of this tutorial, you will see the following screen will be designed.

Load Images From URL Using Fresco

Dependencies

Add the following dependencies in your build.gradle.

implementation 'com.facebook.fresco:fresco:2.3.0'

Make sure you Sync your project after adding the Fresco.

Add Internet Permission

To load images from the internet we are using the URLs, that why we need to add the permission of the INTERNET in our AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET" />

Add the permission when you are loading images from the internet.

Fresco Initialize

Initialize the Fresco before you call setContentView() the function in the MainActivity.

Fresco.initialize(this);

URL for Images

We have the Images URLs and the path where we have to display the images.

val imageUri = Uri.parse("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU6hoB_E1txkSKnkTRiC94dFF1i4BqHXj5_2SLbyYbtDeaM-ITi9emEprFOtXxX_hK_6s&usqp=CAU")
val draweeView = findViewById<View>(R.id.idSDimage) as SimpleDraweeView
draweeView.setImageURI(imageUri)

MainActivity Code

package com.example.handyopinion

import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.view.SimpleDraweeView

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Fresco.initialize(this)
        setContentView(R.layout.activity_main)
        val imageUri = Uri.parse("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU6hoB_E1txkSKnkTRiC94dFF1i4BqHXj5_2SLbyYbtDeaM-ITi9emEprFOtXxX_hK_6s&usqp=CAU")
        val draweeView = findViewById<View>(R.id.idSDimage) as SimpleDraweeView
        draweeView.setImageURI(imageUri)
    }
}


In this tutorial, we learn how to Load Images from URL with Fresco, and we also learned that how we can use the libraries and how we can integrate them into the project.

If you have any questions or suggestions, feel free to ask in the comments section below.

Next Article

1. How to Load Images From URL Using Glide in Android Kotlin
2. How to Load Multiple Images From URL in Android Using Picasso Kotlin
3. How to Load Images From URL Using Fresco in Android Java

Please share this post:
Posts created 35

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: