2015-10-04 146 views
0

我想向圓形ImageView添加圓形的黑色形狀。如何以編程方式向ImageView添加圓形形狀Android

我想是這樣的:

enter image description here

這裏是我的代碼,以使ImageView的圓圈:

private Bitmap getCircleBitmap(Bitmap bitmap) { 
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), 
      bitmap.getHeight(), Bitmap.Config.ARGB_8888); 
    final Canvas canvas = new Canvas(output); 

    final int color = Color.RED; 
    final Paint paint = new Paint(); 
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 
    final RectF rectF = new RectF(rect); 

    paint.setAntiAlias(true); 
    canvas.drawARGB(0, 0, 0, 0); 
    paint.setColor(color); 
    canvas.drawOval(rectF, paint); 

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 
    canvas.drawBitmap(bitmap, rect, rect, paint); 

    bitmap.recycle(); 

    return output; 
} 
+0

具有u看到了這一點https://github.com/Pkmmte/CircularImageView? –

回答

0

如果你想使你的圖片圓形,然後用RoundedImageView作爲解釋在這answer

相關問題