public static Bitmap getRoundedShape(Bitmap scaleBitmapImage,
int targetWidth, int targetHeight, Context context) {
// TODO Auto-generated method stub
// int targetWidth = width;
// int targetHeight = height;
targetHeight = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, targetHeight, (context)
.getResources().getDisplayMetrics());
targetWidth = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, targetWidth, (context)
.getResources().getDisplayMetrics());
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(((float) targetWidth) / 2, ((float) targetHeight) / 2,
(Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
Path.Direction.CCW);
Log.d("", "In process: width" + targetWidth + " height" + targetHeight);
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;
}
No comments:
Post a Comment