3

I want to fill a color inside a canvas , this is my code :

Bitmap bitMap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
bitMap = bitMap.copy(bitMap.getConfig(), true);
Canvas canvas = new Canvas(bitMap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(4.5f);
canvas.drawCircle(50, 50, 30, paint);

This code makes a circle with a border color. How can I fill the circle with a color?

Alexander Farber
  • 19,827
  • 73
  • 224
  • 393
donald draper
  • 521
  • 1
  • 8
  • 24

2 Answers2

13
Paint paint2 = new Paint();      
paint2.setColor(Color.WHITE); 
paint2.setStyle(Style.FILL); 
canvas.drawPaint(paint2); 

You can make the following changes!!

MrRobot9
  • 2,194
  • 3
  • 25
  • 54
6

you need to set corresponding paint style for that, for example Paint.Style.FILL or Paint.Style.FILL_AND_STROKE

greenfrvr
  • 633
  • 6
  • 19