Giter Club home page Giter Club logo

roundedimageview's Introduction

RoundedImageView

A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles) based on the original example from Romain Guy

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 and I'll implement it!

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)

Gradle

RoundedImageView is available in Maven Central.

Add the following to your build.gradle to use:

repositories {
    mavenCentral()
}

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

Usage

Define in xml:

<com.makeramen.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="centerCrop"
        app:corner_radius="30dip"
        app:border_width="2dip"
        app:border_color="#333333"
        app:mutate_background="true"
        app:oval="true" />

Or in code:

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

Or 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

  • 1.3.0

    • 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.
  • 1.2.4

    • 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
  • 1.2.3

    • added rudimentary support for setImageUri. Performance of the function is probably poor and users should be cautious when using it.
  • 1.2.2

    • fix for incorrect radius on the image when there is a border
    • add a toBitmap() function for easier Picasso and Ion compatibility
  • 1.2.1

    • default scaleType now FIT_CENTER (and never null) to match Android (#27)
  • 1.2.0

    • 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
  • 1.1.0

    • LayerDrawable support (needs testing!)
    • Refactored api to support chaining and remove repetitive code
  • 1.0.0

    • Initial release to maven central
    • Programmatically setting attributes with TransitionDrawables not supported.

Bitdeli Badge

roundedimageview's People

Contributors

bencodes avatar bitdeli-chef avatar dkharrat avatar hoeggi avatar kolipass avatar vinc3m1 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.