2014-03-02 170 views
-1
 public static Bitmap getCircularBitmapWithWhiteBorder(Bitmap bitmap, 
     int borderWidth) { 
    if (bitmap == null || bitmap.isRecycled()) { 
     return null; 
    } 
    final int width = bitmap.getWidth() + borderWidth; 
    final int height = bitmap.getHeight() + borderWidth; 
    Bitmap canvasBitmap = Bitmap.createBitmap(width*2, height, Bitmap.Config.ARGB_8888); 
    BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); 
    Paint paint = new Paint(); 
    paint.setAntiAlias(true); 
    paint.setShader(shader); 
    Canvas canvas = new Canvas(canvasBitmap); 
    float radius = width > height ? ((float) height)/2f : ((float) width)/2f; 
    canvas.drawCircle(width/2, height/2, radius, paint); 
    paint.setShader(null); 
    paint.setStyle(Paint.Style.STROKE); 
    paint.setColor(Color.WHITE); 
    paint.setStrokeWidth(borderWidth); 
    canvas.drawCircle(width/2, height/2, radius - borderWidth/2, paint);  
    return canvasBitmap; 
} 

我有圓形的形象,我想接下來的重視圓形圖像不大不小的rectangle..similar的他 enter image description here 這是一個圓圈,旁邊有一個矩形連接。我怎樣才能做到這一點?畫布繪製矩形的Android

+0

正確調整參數,它定位在rectabgle是3面,只有一人失蹤是一個連接到圓形圓形圖片 – user3278732

+0

點擊圖片鏈接查看圖片更好的原因背景稍顯透明http://i.stack.imgur.com/1UGEb.png – user3278732

回答

0

你可以繪製您的矩形或多或少是這樣的:

canvas.drawRect(width/2 + radius, height/2 - radius, width , height, paint); 

只是如果需要

+0

@ user3278732它適合你嗎? – donfuxx