A fast ImageView that supports rounded corners, ovals, and circles.

Overview

RoundedImageView

Maven Central Android Arsenal

A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles) based on the original example from Romain Guy. It supports many additional features including ovals, rounded rectangles, ScaleTypes and TileModes.

RoundedImageView screenshot RoundedImageView screenshot with ovals

There are many ways to create rounded corners in android, but this is the fastest and best one that I know of because it:

  • does not create a copy of the original bitmap
  • does not use a clipPath which is not hardware accelerated and not anti-aliased.
  • does not use setXfermode to clip the bitmap and draw twice to the canvas.

If you know of a better method, let me know (or even better open a pull request)!

Also has proper support for:

  • Borders (with Colors and ColorStateLists)
  • Ovals and Circles
  • All ScaleTypes
    • Borders are drawn at view edge, not bitmap edge
    • Except on edges where the bitmap is smaller than the view
    • Borders are not scaled up/down with the image (correct width and radius are maintained)
  • Anti-aliasing
  • Transparent backgrounds
  • Hardware acceleration
  • Support for LayerDrawables (including TransitionDrawables)
  • TileModes for repeating drawables

Known Issues

  • VectorDrawables are not supported. This library is designed for BitmapDrawables only. Other drawables will likely fail or cause high memory usage.
  • ColorDrawables are poorly supported, use your own rounded VectorDrawables instead if you want less memory pressure.
  • Glide transforms are not supported, please use wasabeef/glide-transformations if you want to round images loaded from Glide.

Gradle

RoundedImageView is available in Maven Central.

Add the following to your build.gradle to use:

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.makeramen:roundedimageview:2.3.0'
}

Usage

Define in xml:

<com.makeramen.roundedimageview.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="fitCenter"
        app:riv_corner_radius="30dip"
        app:riv_border_width="2dip"
        app:riv_border_color="#333333"
        app:riv_mutate_background="true"
        app:riv_tile_mode="repeat"
        app:riv_oval="true" />

Or in code:

RoundedImageView riv = new RoundedImageView(context);
riv.setScaleType(ScaleType.CENTER_CROP);
riv.setCornerRadius((float) 10);
riv.setBorderWidth((float) 2);
riv.setBorderColor(Color.DKGRAY);
riv.mutateBackground(true);
riv.setImageDrawable(drawable);
riv.setBackground(backgroundDrawable);
riv.setOval(true);
riv.setTileModeX(Shader.TileMode.REPEAT);
riv.setTileModeY(Shader.TileMode.REPEAT);

Picasso

To make a Transformation for Picasso:

Transformation transformation = new RoundedTransformationBuilder()
          .borderColor(Color.BLACK)
          .borderWidthDp(3)
          .cornerRadiusDp(30)
          .oval(false)
          .build();

Picasso.with(context)
    .load(url)
    .fit()
    .transform(transformation)
    .into(imageView);

Changelog

see Releases

License

Copyright 2017 Vincent Mi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Add the possibility to round only specific corners.

    Add the possibility to round only specific corners.

    This changeset adds the possibiltiy to specify which corners should be rounded. (see screenshot) This is only implemented for RoundedDrawable. I will add it to RoundedImageView in a further pull request.

    opened by josketres 17
  • CENTER_CROP is not precisely centered if border_width > 0

    CENTER_CROP is not precisely centered if border_width > 0

    It should be translate along with border_width to be drawn correctly.

    RoundedDrawable.java

    private void setMatrix() { ... ... CENTER_CROP: ... ... mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth); // Translate by border_width to both x, y.

    opened by yeusin 15
  • RoundedImageView does not support background

    RoundedImageView does not support background

    Here is code: <com.makeramen.roundedimageview.RoundedImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/card_send_cash_bg" roundedimageview:riv_corner_radius="30dp" />

    It work here.

    But when i use this <com.makeramen.roundedimageview.RoundedImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/card_send_cash_bg" roundedimageview:riv_corner_radius="30dp" />

    It does not work.

    When i inflate the RoundedImageView and setBackgroudDrawable() or setBackground() in RoundedImageView , it not work.

    Does it really not support the background attribute?

    opened by wangdong20 11
  • Error

    Error "styleable cannot be resolved or is not a field"

    I get the following error:

    "styleable cannot be resolved or is not a field"

    on RoundedImageViewer.java.

    Ive added attrs.xml to res/values, but still no luck.

    image

    opened by devloe 10
  • Add support for setImageResource

    Add support for setImageResource

    i think it can be implemented like so:

    @Override public void setImageResource(final int resId) { if (mResId == resId) return; setImageDrawable(getResources().getDrawable(resId)); this.mResId = resId; }

    also, you could make the setImageDrawable a little better, by using:

    @Override public void setImageDrawable(final Drawable drawable) { if (mDrawable == drawable) return; mResId = 0; ...

    of course, this looks more like a patch than a complete solution, since i'm not familiar with the entire code, but it seems to be working fine.

    opened by AndroidDeveloperLB 10
  • Ion + RIV(oval=true) is not ovaled always

    Ion + RIV(oval=true) is not ovaled always

    My app has contact list. ListView avatar + name. Avatars are defined with remote HTTP URIs. Avatars are loaded with Ion. Avatar has default value set. Ion requests set to placeholder and error values with default avatar. So we must get user avatar or default one.

    And here is the problem: errored avatar is not always ovaled. Scrolling ListView to redraw items makes them oval.

    This are errors:

    | look at 10008 & 10009 | look at 10011 | | --- | --- | | screenshot_2015-09-06-14-18-28 | screenshot_2015-09-06-14-18-33 |

    These are redrawen good after scroll:

    | look at 10008 & 10009 | look at 10011 | | --- | --- | | screenshot_2015-09-06-14-18-36 | screenshot_2015-09-06-14-18-40 |

    This is my XML:

    <com.makeramen.roundedimageview.RoundedImageView
            android:id="@+id/I_avatar"
            android:layout_width="@dimen/big_avatar_width"
            android:layout_height="@dimen/big_avatar_height"
            android:adjustViewBounds="true"
            android:contentDescription="User avatar"
            android:scaleType="centerCrop"
            android:src="@drawable/default_avatar"
            app:riv_oval="true" />
    

    This method is called from contacts adapter getView:

    public static void setAvatarWithIon(final ImageView avatarView, final String avatarUri) {
        final int defaultAvatar = R.drawable.default_avatar;
    
        if (avatarUri != null && !avatarUri.isEmpty()) {
            Ion.with(avatarView)
                    .placeholder(defaultAvatar)
                    .error(defaultAvatar)
                    .load(avatar)
            ;
        } else {
            avatarView.setImageResource(defaultAvatar);
        }
    }
    
    opened by b1rdex 9
  • No rounding when used with Glide

    No rounding when used with Glide

    I am trying to use this View in conjunction with the image library Glide (similar to Picasso).

    Scenario is using one RoundedImageView per item within a listview.

    Everything works fine but when I am using a placeholder then the loaded image first gets drawn as a square but when I make the view disappear and then reappear (pulling down and then up, for example) the image is drawn correctly (that is, as a circle with a border)

    ImageView imageViewContactPhoto = ViewHolder.get(view, R.id.imageView_person);
    Glide.with(context)
                    .load(Uri.parse(photoThumbnailURI)) //URI to image from local addressbook
                    .placeholder(R.drawable.icon_emptyperson_filled) //without this line everything works fine
                    .error(R.drawable.icon_emptyperson_filled)
                    .into(imageViewContactPhoto);
    
    <com.makeramen.RoundedImageView
                android:id="@+id/imageView_person"
                android:layout_width="48dp"
                android:layout_height="48dp"
                app:riv_border_width="2dp"
                app:riv_border_color="@android:color/white"
                app:riv_oval="true"/>
    

    any idea to why this happens?

    It seems like its working if I set a placeholder but also call .dontAnimate()

    Glide.with(context)....placeholder(R.drawable.icon_emptyperson_filled).dontAnimate()...
    
    opened by degill 9
  • Different results when using RoundedDrawable/Transformation and RoundedImageView

    Different results when using RoundedDrawable/Transformation and RoundedImageView

    I'm trying to draw people photos in circle (like in G+)

    If I define RoundedImageView in xml:

    <com.makeramen.RoundedImageView
            android:id="@+id/image3"
            android:layout_width="@dimen/size"
            android:layout_height="@dimen/size"
            android:src="@drawable/marcus"
            ci:border_color="@color/ring"
            ci:border_width="@dimen/width"
            ci:corner_radius="@dimen/radius"/>
    

    With next parameters:

    <color name="ring">#ff0000</color>
    <dimen name="size">65dp</dimen>
    <dimen name="radius">32.5dp</dimen><!-- size /2 -->
    <dimen name="width">4dp</dimen>
    

    Photo is drawn as expected (photo 3).

    But if I'm trying to load image using Ion+Transformation or from RoundedDrawable

    RoundedDrawable.fromDrawable(dr))
                    .setBorderWidth(res.getDimensionPixelSize(R.dimen.width))
                    .setCornerRadius(res.getDimensionPixelSize(R.dimen.radius))
                    .setBorderColor(res.getColor(R.color.ring))
                    .setOval(false)
    

    Photo is drawn not in circle, but as rectangle with rounded corners. Also, you may notice, that width of border is also different for circle and rectangle.

    Example: First is using RoundedDrawable, second is using Ion transformation and third is RoundedImageView marcus

    I tried setting bounds for drawables but that didn't help me.

    I can provide whole test project.

    I can solve this issue by defining bigger radius when using transformation, but it seems weird for me.

    opened by marwinxxii 9
  • Currently setting properties order does matters

    Currently setting properties order does matters

    Hi Vince,

    I've been playing a little bit more with the library. I've come to a strange thing,

    I suppose before setting image bitmap or drawable, we should set all vars, but in your adapter (RoundedImageView demo) we can find:

    ((RoundedImageView) view.findViewById(R.id.imageView1)).setImageBitmap(item.mBitmap);
                ((RoundedImageView) view.findViewById(R.id.imageView1)).setScaleType(item.mScaleType);
    
    

    which is very different, as we can see in the list:

    view.findViewById(R.id.imageView1)).setScaleType(item.mScaleType);
    ((RoundedImageView) view.findViewById(R.id.imageView1)).setImageBitmap(item.mBitmap);
                ((RoundedImageView) 
    

    I came to idea you want to use the first one, because, first you set the bitmap and after setting scale you do: invalidate();

    but in the landing page you say:

    iv.setScaleType(ScaleType.CENTER_CROP);
    iv.setCornerRadius(10);
    iv.setBorderWidth(2);
    iv.setBorderColor(Color.DKGRAY);
    iv.setRoundedBackground(true);
    iv.setImageDrawable(drawable);
    iv.setBackground(backgroundDrawable);
    

    so you are setting vars first. Change the order of the sentences in your adapter, and see what happens in the listview, because imagens doesn't display well using the second code...

    Thanks

    opened by cesards 9
  • Implement onSizeChanged

    Implement onSizeChanged

    Awesome library! Noticed one thing, when changing the view orientation the images did not resize correctly. Should be a simple fix.

    http://developer.android.com/reference/android/view/View.html#onSizeChanged(int, int, int, int)

    opened by Queatz 8
  • Support for Volley?

    Support for Volley?

    First off, thank you very much for putting this into a maven-ized library.

    With the official Android documentation mentioning volley (maybe even recommending it), and the open bug for fixing setImageUri, is there any possibility to add support for Volley? Or do you have any advice on using Volley to download and manage the bitmaps for the rounded image view? Perhaps a way to delegate bitmap retrieval and view re-use to Volley's NetworkImageView?

    Thanks for any help.

    opened by townsfolk 8
  • Fatal Exception: java.lang.OutOfMemoryError

    Fatal Exception: java.lang.OutOfMemoryError

    drawableToBitmap method in RoundedDrawable class is causing an OutOfMemoryError image

    the error is thrown on the createBitmap method call, which is being handled by a try catch of Exception, but does not inherit from Exception, image image a try catch of Throwable would solve

    opened by Irineu333 1
  • Display error when layout change caused by screen rotation

    Display error when layout change caused by screen rotation

    1. screen in vertical orientation, all images display well
    2. rotate screen to horizontal, image(the right one) can not auto adjust

    image

    left one, normal ImageView with shape clip, can auto adjust layout change

    <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/main_novel"
            android:background="@drawable/shape_round_outline"
            android:outlineProvider="background" />
    

    right one, RoundedImageView

    <com.makeramen.roundedimageview.RoundedImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/center"
            app:riv_corner_radius="12dp" />
    
    opened by sunbeams001 0
  • Poor Render Quality on Android Version 9

    Poor Render Quality on Android Version 9

    I'm experiencing extremely poor quality rendering on Moto g(7) play Android version 9.

    This only occurs on this device/version, all others render normally. Here is a screenshot of ImageView side by side with RoundedImageView, I have also attached the image asset depicted in the screenshot.

            <com.makeramen.roundedimageview.RoundedImageView
                android:id="@+id/matrix_cell_avatar"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_marginStart="5dp"
                android:layout_marginTop="5dp"
                android:layout_marginEnd="5dp"
                android:scaleType="fitCenter"
                app:riv_mutate_background="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:riv_corner_radius="5dp"/>
    

    Any guidance would be appreciated.

    RoundedImageView image

    ImageView image

    image asset air_conditioner

    opened by sorter 1
Releases(v2.3.0)
  • v2.3.0(Dec 4, 2016)

  • v2.2.1(Oct 19, 2015)

  • v2.2.0(Aug 23, 2015)

    • Fix extra border draw when no border #115
    • Move @Corner constants to Corner.* class and namespace
    • Update to latest target sdk and support library versions.
    Source code(tar.gz)
    Source code(zip)
  • v2.1.2(Jul 28, 2015)

  • v2.1.1(Jul 13, 2015)

  • v2.1.0(Jul 13, 2015)

    • Add APIs for setting different corner radii. Currently only supports a single radius or 0 (allows you to choose which corners to be rounded by setting otheres to 0).
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Jul 13, 2015)

  • v2.0.0(Jul 13, 2015)

    • Package changed from com.makeramen.* to com.makeramen.roundedimageview.*
    • setCornerRadius(int resId) is now setCornerRadiusDimen(int resId) for clarity.
    • Logging fix (#81)
    • ColorFilter support (#73)
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jul 13, 2015)

    • initial ColorDrawable fix for Lollipop(5.0)
    • xml attributes are now namespaced and start with riv_
    • renamed methods mutatesBackground() and mutateBackground(bool)
    Source code(tar.gz)
    Source code(zip)
  • v1.3.1(Jul 13, 2015)

  • v1.3.0(Jul 13, 2015)

    • A new RoundedTransformationBuilder to help build Picasso Transformations
    • slight API changes:
      • all dimensions are now set at floats. ints will be interpreted as dimension resource IDs
      • round_background is now mutate_background, and a RoundedDrawable will no longer be created for the background if mutate_background is false.
    Source code(tar.gz)
    Source code(zip)
  • v1.2.4(Jul 13, 2015)

    • add basic support for ColorDrawable (and other drawables with -1 intrinsic dimens)
    • implementation of the above is known to be buggy in many cases, pull requests welcome
    Source code(tar.gz)
    Source code(zip)
  • v1.2.3(Jul 13, 2015)

  • v1.2.2(Jul 13, 2015)

  • v1.2.1(Jul 13, 2015)

  • v1.2.0(Jul 13, 2015)

    • add setDither and setFilterBitmap method support on RoundedDrawable for tuning bitmap scaling quality
    • improved performance for setImageResource
    • RoundedDrawable constructor is now public
    • Fixed bug where artifact was downloading aar.asc file instead of aar. You no longer need to have @aar specified in the dependency
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jul 13, 2015)

  • v1.0.0(Jul 13, 2015)

Owner
Vince Mi
Vince Mi
Android ImageView that supports different radii on each corner.

SelectableRoundedImageView Note that this project is no longer maintained. Android ImageView that supports different radii on each corner. It also sup

Joonho Kim 1.1k Nov 25, 2022
Adds touch functionality to Android ImageView.

TouchImageView for Android Capabilities TouchImageView extends ImageView and supports all of ImageView’s functionality. In addition, TouchImageView ad

Michael Ortiz 2.6k Jan 1, 2023
A circular ImageView for Android

CircleImageView A fast circular ImageView perfect for profile images. This is based on RoundedImageView from Vince Mi which itself is based on techniq

Henning Dodenhof 14.4k Jan 5, 2023
Custom shaped android imageview components

Shape Image View Provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitma

Siyamed SINIR 2.6k Jan 8, 2023
Android ImageView that handles animated GIF images

GifImageView Android ImageView that handles Animated GIF images Usage In your build.gradle file: dependencies { compile 'com.felipecsl:gifimageview:

Felipe Lima 1.1k Dec 27, 2022
An imageView can auto scroll with device rotating.

PanoramaImageView An imageView can auto scroll with device rotating. ScreenShots Include PanoramaImageView to Your Project With gradle: dependencies {

郭佳哲 2.2k Dec 26, 2022
Powerful and flexible library for loading, caching and displaying images on Android.

Universal Image Loader The great ancestor of modern image-loading libraries :) UIL aims to provide a powerful, flexible and highly customizable instru

Sergey Tarasevich 16.8k Jan 8, 2023
🍂 Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

?? Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

Jaewoong Eum 1.4k Jan 2, 2023
An image loading and caching library for Android focused on smooth scrolling

Glide | View Glide's documentation | 简体中文文档 | Report an issue with Glide Glide is a fast and efficient open source media management and image loading

Bump Technologies 33.2k Jan 7, 2023
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Koushik Dutta 6.3k Dec 27, 2022
A powerful image downloading and caching library for Android

Picasso A powerful image downloading and caching library for Android For more information please see the website Download Download the latest AAR from

Square 18.4k Jan 6, 2023
An Android library for managing images and the memory they use.

Fresco Fresco is a powerful system for displaying images in Android applications. Fresco takes care of image loading and display, so you don't have to

Facebook 16.9k Jan 8, 2023
load-the-image Apply to compose-jb(desktop), Used to load network and local pictures.

load-the-image load-the-image Apply to compose-jb(desktop), Used to load network and local pictures. ?? Under construction It may change incompatibly

lt_taozi 13 Dec 29, 2022
Crop and Rounded Corners added to an ImageView.

SuperImageView Extra features for your ImageView provided in a modularized way Documentation for v2 coming this week. CropImageView An ImageView that

César Díez Sánchez 658 Dec 1, 2022
Crop and Rounded Corners added to an ImageView.

SuperImageView Extra features for your ImageView provided in a modularized way Documentation for v2 coming this week. CropImageView An ImageView that

César Díez Sánchez 657 Jan 5, 2023
Crop and Rounded Corners added to an ImageView.

SuperImageView Extra features for your ImageView provided in a modularized way Documentation for v2 coming this week. CropImageView An ImageView that

César Díez Sánchez 658 Dec 1, 2022
A customizable, animated progress bar that features rounded corners. This Android library is designed to look great and be simple to use 🎉

RoundedProgressBar Easy, Beautiful, Customizeable The RoundedProgressBar library gives you a wide range of customizable options for making progress ba

null 541 Jan 1, 2023
Material Design implementation for Android 4.0+. Shadows, ripples, vectors, fonts, animations, widgets, rounded corners and more.

Carbon Material Design implementation for Android 4.0 and newer. This is not the exact copy of the Lollipop's API and features. It's a custom implemen

null 3k Dec 30, 2022
Material Design implementation for Android 4.0+. Shadows, ripples, vectors, fonts, animations, widgets, rounded corners and more.

Carbon Material Design implementation for Android 4.0 and newer. This is not the exact copy of the Lollipop's API and features. It's a custom implemen

null 3k Jan 9, 2023
A really simple library that help you to display a custom toast with many colors (for : success, warning, danger, info, dark, light, primary...etc ), or with rounded corners, or event with image.

CoolToast A really simple library that help you to display a custom toast with many colors (for : success, warning, danger, info, dark, light, primary

null 21 Dec 20, 2022