Android First Letter Avatar Image Generator โ
Generating the placeholder image for profile name. Takes the first character of a name.
( AvatarImageGenerator Android Library) ๐ Has over 1500 downloads in Bintray ๐ฃ
I like playing on the canvas with the canvas, painting here and there. ๐ (I will soon share an article on google maps with canvas) ๐
With android canvas, one can create beautiful custom view either to increase the visual look or to add a functionality. Recently i was working on a project and I needed an avatar image with the first letter .This is a common feature found in contacts applications and email applications. I had never done this before. To achieve this, I needed a way to generate one or use a custom view, there is an option of Avatarview (android library), but this requires one to replace an Imageview with Avatarview, but i didnโt want to do that.
I wanted a solution that would work with Imageview using Picasso or Glide.
Both Picasso and Glide are the most used image library and they both support placeholder images. This is where the avatar generator would come in.
This is how I implemented it,
To achieve this, we need three classes
Random Colour picker classes
The final AvatarGenerator class , where the actual drawing on the canvas happens, I hope it does not look scary, It is step by step , creating all the resources needed and finally painting on the canvas. The avatarImage function returns an BitmapDrawable that can be used in an imageView.
With the above classes we can now set an avatar to an ImageView using Picasso and Glide.
The avatar generator supports two shapes, a circle and square. An avatar is created by passing the context, width , shape and the name just as in the above examples.
If you need a quick solution, then you can use the library I created basing on the above classes, AvatarImageGenerator . You are welcome to contribute. ๐