Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using picasso library with a circle image view

I am looking at using the Picasso library to download an image from URL and pass this into circle image view, but since picasso requires that you pass in an actual imageView I have come to a standstill on how to do it

I am using the picasso library from here http://square.github.io/picasso/ and the circle image view class from here https://github.com/hdodenhof/CircleImageView

Here is the start of my code to get the image

private void getData() {

    userName.setText(prefs.getString("userName",""));
    jobTitle.setText(prefs.getString("profile",""));
    userLocation.setText(prefs.getString("location",""));




    // ??????    

    // Picasso.with(context).load(image link here).into(imageview here);

    //CircleImageView img = new CircleImageView(this);
    //img.setImageResource();
    //img.setImageBitmap();
    //img.setImageDrawable();
    //img.setImageURI();

}

Edit:

here is the xml for the circleImageView

<michael.CircleImageView
 android:layout_width="100dp"
 android:layout_height="100dp"
 android:src="@drawable/shadow"
 android:layout_gravity="center"
 android:layout_marginTop="16dp"
 app:border_width="2dp"
 app:border_color="#274978"
 android:id="@+id/circleImageView"
like image 584
MichaelStoddart Avatar asked Jun 05 '15 10:06

MichaelStoddart


People also ask

How do you load an image into an imageView from an image URL using Picasso?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.

Can Picasso load GIF?

Picasso does not support GIF animation on a simple image view. Glide loads images faster than Picasso.


2 Answers

I don't think you require CircleImageView library

You can implement Circular Transformation check the below gist

https://gist.github.com/julianshen/5829333

then

Picasso.with(activity).load(image link here)
     .transform(new CircleTransform()).into(ImageView);
like image 124
Yogesh Narayanan Avatar answered Oct 03 '22 01:10

Yogesh Narayanan


Use This

Activity Class

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String imageUrl = "https://www.baby-connect.com/images/baby2.gif";

        CircleImageView imageView = (CircleImageView) findViewById(R.id.image);

        Picasso.with(getApplicationContext()).load(imageUrl)
                .placeholder(R.drawable.images).error(R.drawable.ic_launcher)
                .into(imageView);
    }
}

Layout File

<de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/image"
    android:layout_width="160dp"
    android:layout_height="160dp"
    android:layout_centerInParent="true"
    android:src="@drawable/images"
    app:border_color="#ffffff"
    app:border_width="2dp" />

This is Working fine.

like image 38
Sandeep Singh Avatar answered Oct 03 '22 01:10

Sandeep Singh