Rounded imageview android library

Rounded imageview android library

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

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 ScaleType s
    • 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)

RoundedImageView is available in Maven Central.

Add the following to your build.gradle to use:

Or make a Transformation for Picasso:

1.3.0

  • A new RoundedTransformationBuilder to help build Picasso Transformation s
  • slight API changes:
    • all dimensions are now set at float s. int s 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.
Читайте также:  Как включить проценты зарядки андроид

About

a fast ImageView that supports rounded corners and ovals or circles

Источник

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

Overview

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.

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 ScaleType s
    • 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
  • 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.

RoundedImageView is available in Maven Central.

Источник

Rounded imageview android library

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.

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 ScaleType s
    • 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
  • 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.
Читайте также:  Kaspersky internet security android обзор

RoundedImageView is available in Maven Central.

Источник

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

Overview

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.

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 ScaleType s
    • 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
  • 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.

RoundedImageView is available in Maven Central.

Источник

Rounded imageview android library

Shape Image View

Provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitmap mask based image views.

  • Shader based one uses canvas draw methods and Path class,
  • Mask based one uses xfermode to draw image on bitmaps defined by android shape XML’s or resource bitmaps.

There are many projects online implementing such components, however one goal of this project is to provide a performant/smooth scrolling image view component framework to define different shapes for imageviews.

Читайте также:  Radiobutton android studio кастомизация

For use with recycling view such as ListView or GridView please use shader based implementations.

###Shader Based ImageView’s ####BubbleImageView

  • siTriangleHeight the height of the bubble pointer in dp
  • siArrowPosition where to point the arrow, currently left|right
  • siSquare set width and height to the minimum of the given values true|false

####RoundedImageView

  • siBorderColor border color
  • siBorderWidth border width in dp
  • siBorderAlpha alpha value of the border between 0.0-1.0
  • siRadius corner radius in dp
  • siSquare set width and height to the minimum of the given values true|false

####CircularImageView

  • siBorderColor border color
  • siBorderWidth border width in dp
  • siBorderAlpha alpha value of the border between 0.0-1.0

####ShapeImageView This view has the capability to process a provided SVG file (for a limited set of SVG elements), build a Path object and draw it on the shader. The library includes SVG files defining a set of basic shapes and ShapeImageView subclasses using those files. You can use whatever SVG you want to have a wonderful and creatively shaped images in your application. The included SVG files are under library/src/main/res/raw

DiamondImageView PentagonImageView HexagonImageView
OctogonImageView StarImageView HeartImageView
  • siBorderColor border color
  • siBorderWidth border width in dp
  • siBorderAlpha alpha value of the border between 0.0-1.0
  • siStrokeCap border stroke cap type butt|round|square
  • siStrokeJoin border stroke join type bevel|miter|round
  • siSquare set width and height to the minimum of the given values true|false
  • siShape a reference to an SVG. This is used by ShapeImageView, not the subclasses of it.

SVG elements that are supported are: rectangle, circle, ellipse, polygon, path, group. Transformations on those elements are also supported.

The system converts an SVG file into a Path. For each element including the parent element a new Path is created, and all the children Path’s are added to their parent path.

###Bitmap Mask Based ImageViews

This view uses extra bitmaps for bitmap masks. Therefore it would be good to use them for very custom shapes, possibly not in a recycling view.

rounded rectangle shape definition in XML:

  • siShape the bitmap mask shape, either a shape drawable or a bitmap
  • siSquare set width and height to the minimum of the given values true|false

This method reads a shape file (either bitmap or an android shape xml), creates a bitmap object using this shape, and finally combines the bitmap of the real image to be shown and the mast bitmap using xfermode.

See/execute the sample for a demonstration of the components.

If you are lazy check this youtube video demonstrating scrolling in the sample app

Источник

Оцените статью