Crop image in circular shape in android.
Public Class Rounder{
}
and use it as
Bitmap roundedBitmapImage=new Rounder().getRoundedShape(YourNormalBitmapImage);
Public Class Rounder{
           public Bitmap getRoundedShape(Bitmap scaleBitmapImage) { 
            int targetWidth = 125;
            int targetHeight = 125;  
           Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,            targetHeight,Bitmap.Config.ARGB_8888); 
         Canvas canvas = new Canvas(targetBitmap);  
         Path path = new Path(); 
         path.addCircle(((float) targetWidth - 1) / 2,
 ((float) targetHeight - 1) / 2,
 (Math.min(((float)     targetWidth), 
 ((float) targetHeight)) / 2),
 Path.Direction.CCW); 
        canvas.clipPath(path); 
        Bitmap sourceBitmap = scaleBitmapImage; 
       canvas.drawBitmap(sourceBitmap, 
 new Rect(0, 0, sourceBitmap.getWidth(),    sourceBitmap.getHeight()), 
 new Rect(0, 0, targetWidth,
 targetHeight), null); 
 return targetBitmap;
 }
}
and use it as
Bitmap roundedBitmapImage=new Rounder().getRoundedShape(YourNormalBitmapImage);
No comments:
Post a Comment