---
title: "How to set an image on ImageView in android?"  
description: "How to set an image on ImageView in android?"  
author: "Arti Mishra"  
published: 2018-08-22  
updated: 2023-07-02  
canonical: https://www.mindstick.com/forum/34664/how-to-set-an-image-on-imageview-in-android  
category: "android apps"  
tags: ["android"]  
reading_time: 3 minutes  

---

# How to set an image on ImageView in android?

How to set a circular [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) on ImageView, coming from the server.

## Replies

### Reply by Aryan Kumar

Sure, here is how to set an image on image view in Android:

Code snippet

```plaintext
public void setImage(Bitmap image) {
    // Get the image view
    ImageView imageView = findViewById(R.id.imageView);

    // Set the image in the image view
    imageView.setImageBitmap(image);
}
```

This code will first get the image view by calling the `findViewById()` method. Then, it will set the image in the image view by calling the `setImageBitmap()` method of the image view.

The `setImageBitmap()` method has one parameter:

- The bitmap that will be displayed in the image view.

The bitmap can be obtained from a variety of sources, such as:

- A file on the device's storage.
- A resource in the app's resources.
- A stream of data.

To use this code, you would need to call the `setImage()` method in your app. For example, you could call the method in your app's `onCreate()` method.

Here is an example of how you could call the `setImage()` method in your app's `onCreate()` method:

Code snippet

```plaintext
public void onCreate() {
    super.onCreate();

    // Create an image view to display the image
    imageView = findViewById(R.id.imageView);

    // Load the image from a file
    Bitmap image = BitmapFactory.decodeFile("path/to/image.jpg");

    // Set the image in the image view
    imageView.setImageBitmap(image);
}
```

When you run the app, you will see an image view with the image that you loaded from the file.

### Reply by Arti Mishra

## /* Create an object of ImageView */

ImageView myImage= (ImageView) findViewById(R.id.edit_image);

## /* Picasso is a powerful image downloading and caching library.*/

Picasso.with(getApplicationContext())

.load("https://www.mysite.com//Contents/images/User%20Image/"+SaveSharedPreference.getPrefUserId(this) + ".png")

.transform(new CircleTransformation())

.into(myImage);

\

## CircleTransformation.java

package com.example.msclient010.mindstickqna.Utils;

import android.graphics.Bitmap;

import android.graphics.BitmapShader;

import android.graphics.Canvas;

import android.graphics.Paint;

import com.squareup.picasso.Transformation;

/**

* Created by msclient010 on 2/2/2018.

*/

public class CircleTransformation implements Transformation {

@Override

public Bitmap transform(Bitmap source) {

int size = Math.min(source.getWidth(), source.getHeight());

int x = (source.getWidth() - size) / 2;

int y = (source.getHeight() - size) / 2;

Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);

if (squaredBitmap != source) {

source.recycle();

}

Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());

Canvas canvas = new Canvas(bitmap);

Paint paint = new Paint();

BitmapShader shader = new BitmapShader(squaredBitmap,

BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);

paint.setShader(shader);

paint.setAntiAlias(true);

float r = size / 2f;

canvas.drawCircle(r, r, r, paint);

squaredBitmap.recycle();

return bitmap;

}

@Override

public String key() {

return "circle";

}

}

\


---

Original Source: https://www.mindstick.com/forum/34664/how-to-set-an-image-on-imageview-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
