List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawable setGravity
public void setGravity(int i)
From source file:com.yk.notification.util.BitmapUtil.java
/** * //from www. j av a 2 s . c om * @param bitmap * @return */ public static Bitmap createRoundImageWithBorder(Context context, Bitmap bitmap) { // int bitmapWidth = bitmap.getWidth(); // int bitmapHeight = bitmap.getHeight(); // pixel int borderWidthHalf = 20; //?? int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight); //? int newBitmapSquareWidth = bitmapSquareWidth + borderWidthHalf; Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquareWidth, newBitmapSquareWidth, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(roundedBitmap); int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth; int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight; //???,?X,Y?2 ?? canvas.drawBitmap(bitmap, x / 2, y / 2, null); Paint borderPaint = new Paint(); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidthHalf); borderPaint.setColor(Color.WHITE); // canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquareWidth / 2, borderPaint); RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), roundedBitmap); roundedBitmapDrawable.setGravity(Gravity.CENTER); roundedBitmapDrawable.setCircular(true); return getBitmapFromDrawable(roundedBitmapDrawable); }