5

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
  • 21,519
  • 75
  • 241
  • 416
donald draper
  • 561
  • 2
  • 9
  • 24

2 Answers2

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

You can make the following changes!!

MrRobot9
  • 2,402
  • 4
  • 31
  • 68
6

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

greenfrvr
  • 643
  • 6
  • 19