Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
ImageView in Android using Jetpack Compose
Next article icon

ImageView in Android using Jetpack Compose

Last Updated : 20 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Images, graphics, and vectors attract many users as they provide a lot of information in a very informative way. ImageView in Android is used to display different types of images, from drawables to Bitmaps. In this article, we will take a look at the implementation of an ImageView in Android using Jetpack Compose. 

Attributes of ImageView Widget

Attributes

Description

painterthe painter resource used to draw the image. Here, painterResource is used to load an image from the resources.
bitmapto add a bitmap for your image inside imageview.
modifierto add padding to imageview
contentScaleto add scaling to our image to fit our image inside imageview
alphato add alpha to our imageview.
colorFilterto add colors to our imageview. 
blendModeto add color effects to our imageview. 

contentDescription

to describe the content of the image for accessibility.

alignment

to align the content within the bounds of the Image

Step-by-Step Implementation

Step 1: Create a New Project

To create a new project in the Android Studio Canary Version please refer to How to Create a new Project in Android Studio Canary Version with Jetpack Compose.

Step 2: Add an Image to the drawable folder

After creating a new project we have to add an image inside our drawable folder for displaying that image inside our ImageView. Copy your image from your folder's location and go inside our project. Inside our project Navigate to the app > res > drawable > Right-click on the drawable folder and paste your image there. 

imageview-compose-dir


Step 3: Working with the MainActivity.kt file

After adding this image navigates to the app > java > MainActivity.kt and add the below code to it. Comments are added inside the code for a detailed explanation. 

MainActivity.kt:

MainActivity.kt
package org.geeksforgeeks.demo  import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.* import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.* import androidx.compose.ui.graphics.* import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import org.geeksforgeeks.demo.ui.theme.DemoTheme  class MainActivity : ComponentActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         enableEdgeToEdge()         setContent {             DemoTheme {                 // A surface container using the                 // 'background' color from the theme                 Surface(                     // to add background color for our screen.                     color = MaterialTheme.colorScheme.background,                 ) {                     // at below line we are calling                     // our function for image view.                     ImageExample()                 }             }         }     } }  @Composable fun ImageExample() {     Column(         // we are using column to align our         // imageview to center of the screen.         modifier = Modifier             .fillMaxWidth()             .fillMaxHeight(),          // below line is used for specifying         // vertical arrangement.         verticalArrangement = Arrangement.Center,          // below line is used for specifying         // horizontal arrangement.         horizontalAlignment = Alignment.CenterHorizontally,     ) {         // below line is used for creating a variable         // for our image resource file.         val painter = painterResource(id = R.drawable.gfg_logo)          // below is the composable for image.         Image(             // first parameter of our Image             // is our image path which we have created             // above             painter = painter,             contentDescription = "Sample Image",              // below line is used for creating a modifier for our image             // which includes image size, padding and border             modifier = Modifier                 .height(300.dp)                 .width(300.dp)                 .padding(16.dp)                 .border(2.dp, Color.Black, CircleShape),              // below line is used to give             // alignment to our image view.             alignment = Alignment.Center,              // below line is used to scale our image             // we are using fit for it.             contentScale = ContentScale.Fit,              // below line is used to define the opacity of the image.             // Here, it is set to the default alpha value, DefaultAlpha.             alpha = DefaultAlpha,         )     } }  // @Preview function is use to see preview // for our composable function in preview section. @Preview(showSystemUi = true) @Composable fun ImageExamplePreview() {     // we are passing our composable     // function to display its preview.     ImageExample() } 

Output:

imageview-compose


Next Article
ImageView in Android using Jetpack Compose

C

chaitanyamunje
Improve
Article Tags :
  • Technical Scripter
  • Android
  • Technical Scripter 2020
  • Android-Jetpack

Similar Reads

    Circular ImageView in Android using Jetpack Compose
    Circular ImageView is used in many of the apps. These types of images are generally used to represent the profile picture of the user and many more images. We have seen the implementation of ImageView in Android using Jetpack Compose. In this article, we will take a look at the implementation of Cir
    2 min read
    Image Color Picker in Android using Jetpack Compose
    Many android applications require functionality in which the user should be able to pick the color from the image which is present within the android application. In this article, we will take a look at How to implement Image Color Picker in Android applications using Jetpack Compose. We will be abl
    5 min read
    Staggered GridView in Android using Jetpack Compose
    Staggered Grid View has been seen in most applications such as Pinterest in which each item of gridview takes its own height and aligns within the grid view according to that. In this article, we will look at how to implement Staggered Grid View in Android using Jetpack ComposeStep by Step Implement
    4 min read
    Text in Android using Jetpack Compose
    Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. Android Text is a simple view in Android which is used to display text inside our App. In this article, we will take a look at the implementation of Text in Android using Jetpack Compose. Importan
    5 min read
    Curved Text in Android using Jetpack Compose
    In Android, there are no inbuilt schemes to implement designed text like the word art, which is available in applications like MS Word. We can always refer to or download such schemes like designed font faces to implement designed text. However, it is also possible to natively build (building from s
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences