Custom shaped android imageview components

Overview

Shape Image View

Maven Central

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.

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

Sample app in play store

Youtube video

How to use

Gradle dependency:

compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

###Shader Based ImageView's ####BubbleImageView Android Bubble ImageView

<com.github.siyamed.shapeimageview.BubbleImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siArrowPosition="right"
    app:siSquare="true"/>

Attributes:

  • 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 Android Rounded Rectangle ImageView

<com.github.siyamed.shapeimageview.RoundedImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siRadius="6dp"
    app:siBorderWidth="6dp"
    app:siBorderColor="@color/darkgray"
    app:siSquare="true"/>

Attributes:

  • 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 Android Circular ImageView

<com.github.siyamed.shapeimageview.CircularImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siBorderWidth="6dp"
    app:siBorderColor="@color/darkgray"/>

Attributes:

  • 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
Android Diamond ImageView Android Pentagon ImageView Android Hexagon ImageView
OctogonImageView StarImageView HeartImageView
Android Octogon ImageView Android Start ImageView Android Heart ImageView
<com.github.siyamed.shapeimageview.{ClassName}
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="8dp"
    android:src="@drawable/neo"
    app:siBorderWidth="8dp"
    app:siBorderColor="@color/darkgray"/>

Attributes:

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

Android Star Shape ImageView

<com.github.siyamed.shapeimageview.mask.PorterShapeImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:siShape="@drawable/star"
    android:src="@drawable/neo"
    app:siSquare="true"/>

Android Star Shape ImageView

<com.github.siyamed.shapeimageview.mask.PorterShapeImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:siShape="@drawable/shape_rounded_rectangle"
    android:src="@drawable/neo"
    app:siSquare="true"/>

rounded rectangle shape definition in XML:

<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
        android:topLeftRadius="18dp"
        android:topRightRadius="18dp"
        android:bottomLeftRadius="18dp"
        android:bottomRightRadius="18dp" />
    <solid android:color="@color/black" />
</shape>

Attributes:

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

Sample

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

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

You can download the sample app from play store

Proguard

-dontwarn android.support.v7.**
-keep class android.support.v7.** { ; }
-keep interface android.support.v7.* { ; }
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.**{ *; }

References

Android Shape Image View on Android Arsenal

Comments
  • License

    License

    Siyamed, thank you for great library. I would love to use in my project but I have a small problem with your license.

    Apache License 2.0 standard legal line typically begins with: Copyright {yyyy} {name of copyright owner} In the case of your Android-ShapeImageView, only the subsequent “Licensed under the Apache License, Version 2.0 ...” is listed without any copyright owner preceding it.

    Would you mind adding your copyright information to it? thank you, Janusz

    opened by izotx 3
  • The widget can't work well in the RelativeLayout

    The widget can't work well in the RelativeLayout

    When I used ithe CircularImageView in the RelativeLayout, I found I can't define the size of the view with fixed dp which work well in the LinearLayout. Can't it be fit?

    opened by zsigui 3
  • attrs shape and radius already defined

    attrs shape and radius already defined

    Hi, I am trying to add the aar using gradle as below compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

    upon using find tool I found that radius is already used my ViewPagerIndicator, because of which I am unable to add the library.

    Is there any workaround to change the attrs name so that I can add it into my project?

    opened by rinav 3
  • Black line when roundedimageview used issue

    Black line when roundedimageview used issue

    hi, great library thanks for all of it. I have an issue when I try to use your roundedimageview view. This is my xml define : <com.github.siyamed.shapeimageview.RoundedImageView android:id="@+id/iv_message_image" android:layout_width="250dp" android:layout_height="match_parent" android:contentDescription="@string/app_name" android:scaleType="fitXY" app:siRadius="11dp" app:siBorderWidth="2dp" android:padding="1dp" app:siBorderColor="@color/chat_bubble_green" app:siSquare="true" android:src="@drawable/profile" />

    In the top layout I have a linearlayout which has a 9 png as background. Anyway this implementation is in a recyclerview. And some items in that view some of the roundedimageview's side have black line. This is what I want to mean : issue

    Any ideas? Thanks...

    opened by hellsayenci 2
  • What is the Latest version of this Library?

    What is the Latest version of this Library?

    Your library is very useful. Thank You.

    The version as seen in the below statement is 0.9+ and android studio throws a warning for such statements. compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

    Can you tell me whats the new version is ??

    opened by iAviatorJose 2
  • Update android sdk

    Update android sdk

    I've updated

    • gradle wrapper
    • target/compile version (in sample)
    • .gitignore

    Lib can now working on current android studio versions. See https://github.com/siyamed/android-shape-imageview/issues/25 too

    opened by StefMa 2
  • CircularImageView has no size until it draws itself

    CircularImageView has no size until it draws itself

    It's using a fixed width and height, but in the editor it has width/height of 0. At runtime, it has width/height of 0 until it draws something. This is a problem because it's in a RelativeLayout and other views are aligned to it, which makes them shift in front of you.

    I looked at the onMeasure code and I can't see why this happens.

    I am settings its content with Picasso, but that shouldn't matter - the size is fixed so it should never be getting resized.

    <com.github.siyamed.shapeimageview.CircularImageView android:id="@+id/user_photo_image_view" android:layout_width="66dp" android:layout_height="66dp" />

    My workaround is to put it inside of a LinearLayout that has a fixed size.

    opened by bsegall 2
  • Not work with Glide

    Not work with Glide

    Hi,

    I'm using Glide to load an image to your DiamondImageView and it show as square. But it work well with Picasso. So, without using Picasso do you have any hint for it?

    opened by langhoangal 1
  • Rounded Hexagon

    Rounded Hexagon

    It seems that i can't make my hexagon corners go round

    <com.github.siyamed.shapeimageview.HexagonImageView
                            android:layout_width="@dimen/profile_picture_size"
                            android:layout_height="@dimen/profile_picture_size"
                            android:src="@drawable/neo"
                            app:siBorderWidth="10dp"
                            app:siBorderColor="@color/blue"
                            app:siRadius="10dp"
                            android:layout_alignParentTop="true"
                            android:layout_centerHorizontal="true"
                            android:id="@+id/view_profile_pic"
                            android:scaleType="centerCrop"/>
    

    Am I doing it wrong?

    opened by ronzohan 1
  • i cant it libery in eclipce

    i cant it libery in eclipce

    hi dear, I want libery android-shape-imageview import into eclipse but i cant.i want just diamond shape image view

    Is it possible for me to put diamond class ????

    opened by iman100 1
  • CenterInside not working with pentagonImageView

    CenterInside not working with pentagonImageView

    I have an image with scaletype centerInside but isn't working, i have this: <com.github.siyamed.shapeimageview.PentagonImageView android:layout_width="match_parent" android:layout_height="75dp" android:src="@drawable/restaurant" android:scaleType="centerInside" />

    opened by chriscoderdr 1
  • com.github.siyamed.shapeimageview.mask.PorterShapeImageView cannot be cast to com.github.siyamed.shapeimageview.ShapeImageView

    com.github.siyamed.shapeimageview.mask.PorterShapeImageView cannot be cast to com.github.siyamed.shapeimageview.ShapeImageView

    2021-11-03 05:03:38.494 1069-1069/com.wisdom E/AndroidRuntime: FATAL EXCEPTION: main Process: com.wisdom, PID: 1069 java.lang.ClassCastException: com.github.siyamed.shapeimageview.mask.PorterShapeImageView cannot be cast to com.github.siyamed.shapeimageview.ShapeImageView at com.wisdom.Adapters.Adap_PostList$ViewHolder.(Adap_PostList.kt:58) at com.wisdom.Adapters.Adap_PostList.onCreateViewHolder(Adap_PostList.kt:22) at com.wisdom.Adapters.Adap_PostList.onCreateViewHolder(Adap_PostList.kt:17) at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114) at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303) at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627) at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587) at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851) at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at androidx.swiperefreshlayout.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:625) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635) at android.widget.LinearLayout.onLayout(LinearLayout.java:1544) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635) at android.widget.LinearLayout.onLayout(LinearLayout.java:1544) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635) at android.widget.LinearLayout.onLayout(LinearLayout.java:1544) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:761) at android.view.View.layout(View.java:19663) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2500) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2216) 2021-11-03 05:03:38.496 1069-1069/com.wisdom E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1396) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6773) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966) at android.view.Choreographer.doCallbacks(Choreographer.java:778) at android.view.Choreographer.doFrame(Choreographer.java:713) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6518) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

    opened by nishtechs 0
  • Not working in android 11

    Not working in android 11

     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.kxml2.io.KXmlParser" on path: DexPathList[[zip file "/data/app/~~M1SVM_YRJj949STHA9_Ppw==/com.example.harmika-68oS_spdM2YYjsUaFX5CTg==/base.apk"],nativeLibraryDirectories=[/data/app/~~M1SVM_YRJj949STHA9_Ppw==/com.example.harmika-68oS_spdM2YYjsUaFX5CTg==/lib/x86, /data/app/~~M1SVM_YRJj949STHA9_Ppw==/com.example.harmika-68oS_spdM2YYjsUaFX5CTg==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
    
    opened by talha01sayed 0
  • android shape imageview & NavigationView Error

    android shape imageview & NavigationView Error

    Hi, when I add this library to Bildgradle , without writing any code, it unfortunately gets a Error from my navigation menu :

    Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class com.google.android.material.navigation.NavigationView Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.google.android.material.navigation.NavigationView

    opened by sami-soft 0
  • border wont be able to show transparent color!!!

    border wont be able to show transparent color!!!

    when using the transparent color like : app:siBorderColor="@color/color_transparent" -->( @color/color_transparent = "#26ff00ff")<-- nothing happen at all, and the border draw as a white color and ignored the transparent.

    opened by AliAsadiPGI 0
Releases(0.9.3)
Owner
Siyamed SINIR
Padawan @ Somewhere
Siyamed SINIR
Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.

Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.

Nosakhare Belvi 115 Dec 20, 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
Custom view for circular images in Android while maintaining the best draw performance

CircularImageView Custom view for circular images in Android while maintaining the best draw performance Usage To make a circular ImageView, add this

Pkmmte Xeleon 1.2k Dec 28, 2022
Android Fading (Circle/ Custom Corner) Image

Android Fading (Circle/ Custom Corner) Image Implementation add maven { url 'https://jitpack.io' } to build.gradle in your project: allprojects {

Aghiad Odeh 1 Jul 5, 2022
Phimp.me Android Phimp.me is an Android image editor app

Phimp.me Android Phimp.me is an Android image editor app that aims to replace proprietary photographing and image apps on smart phones. It offers feat

FOSSASIA 2.6k Jan 6, 2023
Opencv Android SDK application for Deep Neural Networks to run on Android.

This application allows you to deploy deep nets in Android environment using OpenCV Android SDK. With OpenCV, images are taken from the camera on your phone, and then these images are passed through the neural network and visualized on the front side. In this application, we will search for faces in the images taken and draw the found faces on the screen.

Ahmet Furkan DEMIR 10 Nov 1, 2022
Android filters based on OpenGL (idea from GPUImage for iOS)

GPUImage for Android Idea from: iOS GPUImage framework Goal is to have something as similar to GPUImage as possible. Vertex and fragment shaders are e

CATS Open Source Softwares 8.6k Dec 28, 2022
Android library project for cropping images

I guess people are just cropping out all the sadness An Android library project that provides a simple image cropping Activity, based on code from AOS

Jamie McDonald 4.5k Jan 7, 2023
some android image filters

android-image-filter some android image filters in some filter, I use NDK to implement to make it more efficient Setup Install Android NDK and properl

RagnarokStack 643 Dec 27, 2022
An android image compression library.

Compressor Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller

Zetra 6.7k Dec 31, 2022
Android widget for cropping and rotating an image.

Cropper The Cropper is an image cropping tool. It provides a way to set an image in XML and programmatically, and displays a resizable crop window on

Edmodo 2.9k Nov 14, 2022
A simple image cropping library for Android.

SimpleCropView The SimpleCropView is an image cropping library for Android. It simplifies your code for cropping image and provides an easily customiz

Issei Aoki 2.5k Dec 28, 2022
Customizable Android full screen image viewer for Fresco library supporting "pinch to zoom" and "swipe to dismiss" gestures. Made by Stfalcon

This project is no longer supported. If you're able to switch from Fresco to any other library that works with the Android's ImageView, please migrate

Stfalcon LLC 1.8k Dec 19, 2022
Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.

Dali Dali is an image blur library for Android. It is easy to use, fast and extensible. Dali contains several modules for either static blurring, live

Patrick Favre-Bulle 1k Dec 1, 2022
An image resizing library for Android

Resizer Inspired by zetbaitsu's Compressor, Resizer is a lightweight and easy-to-use Android library for image scaling. It allows you to resize an ima

Kakit Ho 426 Dec 22, 2022
Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.

ChiliPhotoPicker Made with ❤️ by Chili Labs. Library made without DataBinding, RxJava and image loading libraries, to give you opportunity to use it w

Chili Labs 394 Nov 29, 2022
Simple android image popup Library

Android Image Popup Show image as a popup on a click event or any event. Simply set the image as drawable and thats it!!!. And also you can set width,

Chathura Lakmal 64 Nov 15, 2022
Image loading library for Android

Image Loader Image loader library for Android. Deprecated. See Glide. Features Image transformations Automatic memory and storage caching Ability to l

Yuriy Budiyev 19 May 28, 2022
SVG to Android VectorDrawable XML resource file

svg2android [Deprecated - use official Vector Asset Studio directly from Android Studio] Convert SVG to Android VectorDrawable XML resource file. Extr

INLOOPX 1.7k Dec 29, 2022