how to create circle image android for profile - SpartaCode

SpartaCode

Make your development faster and easier !

how to create circle image android for profile



Circle images are used for profile image to make it unique and different. Examples can be found in whatsup and hike,etc.
Here is simple tutorial demonstrating creation of such round image.

Before we get started,

Download this file and place it into your project 



What exactly is process ?

RoundImage constructor accepts bitmap image as its parameter or input.
Than it converts that bitmap image into round according to its calculations.
This object of round image will be used to set imageview.
  

Step 1 : Create object of RoundImage


 

RoundImage roundimage = new RoundImage(bitmap);



Where,

bitmap : Object of class Bitmap or a bitmap image.

Here to get bitmap image you have to take some efforts.

How to convert ImageUri into Bitmap Image ?

Use following code to convert ImageUri to Bitmap image :


 

Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageuri);




When your image is on your device i.e in your mobiles external storage use following code to get it and set as round image.




File file =new File(imagepathindevice);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), bmOptions);
RoundImage roundimage= new RoundImage(bitmap);
imageView.setImageDrawable(roundimage);



where,
 file.getAbsolutePath() can be replaced by your path in external storage like 



Environment.getExternalStorageState()




Hence, 
 you require some effort to get bitmap image to make it round.


Step 2 : Set round image to Imageview


yourimageView.setImageDrawable(roundimage);



Thank you 
Please Like and Subscribe 


No comments:

Post a Comment

News

Get Amazing Traffic to your Site

Traffic Exchange

Post Bottom Ad

Responsive Ads Here