2014-03-02 5 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; 
} 
나는 원형 이미지가

, 내가 옆에있다,이 원 그의 enter image description here 에 rectangle..similar의 원형 이미지 정렬 옆에 첨부 할 안드로이드 사각형을 그립니다 직사각형이 붙어있다. 내가 어떻게 할 수 있니?캔버스

+0

를 필요한 경우

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

그냥 제대로 위치에 대한 매개 변수를 조정은 rectabgle는 단지 하나의 누락은 둥근에 부착 한 3면입니다 circular image – user3278732

+0

이미지를 보려면 이미지 링크를 클릭하십시오. 더 나은 배경은 다소 투명합니다. http://i.stack.imgur.com/1UGEb.png – user3278732

답변

0

당신은 더 많거나 적은이처럼 사각형을 그릴 수 :

+0

@ user3278732 효과가 있었습니까? – donfuxx