public static Bitmap drawCircle(int width,int height, int borderWidth) {
Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(canvasBitmap, TileMode.CLAMP,
TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
paint.setShader(null);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.WHITE);
paint.setStrokeWidth(borderWidth);
Canvas canvas = new Canvas(canvasBitmap);
float radius = width > height ? ((float) height)/2f : ((float) width)/2f;
canvas.drawCircle(width/2, height/2, radius - borderWidth/2, paint);
return canvasBitmap;
}
簡單的代碼繪製一個帶有白色邊框的圓圈,但是我希望邊框的一部分是黑色的而另一部分是白色的。其中40%爲黑色,60%爲白色繪製不同邊框顏色的圓Android
這怎麼辦?
你正在路上。而不是畫圓,畫兩個弧。一個白色,另一個黑色。請參閱'canvas.drawArc(...)'。做一些簡單的數學運算... –
我是probabl; y有drawarc params的問題,例如這不會給我畫任何東西RectF rect = new RectF(10,10,10,10); \t \t canvas.drawArc(rect,0,180,true,paint); – user3278732