1

I wants to draw Circle on empty canvas, but not getting how to do. This is code I'm using to create Empty canvas inside my custom ImageView class.

bmpBase = Bitmap.createBitmap(image_width, image_height, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bmpBase);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
canvas.drawCircle(100, 100, 30, paint);
Emran Sadeghi
  • 612
  • 6
  • 20
Arpana
  • 342
  • 1
  • 3
  • 13

2 Answers2

3

try this, in your MainActivity first find your imageView and then:

                drawingImageView = (ImageView)findViewById(R.id.DrawingImageView);
                Paint paint = new Paint();
                paint.setColor(Color.BLUE));
                paint.setStyle(Paint.Style.STROKE);
                paint.setStrokeWidth(15);    
                bmpBase = Bitmap.createBitmap(image_width, image_height, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                canvas.drawCircle(100, 100, 30, paint);
                drawingImageView.setImageBitmap(bitmap);
mmlooloo
  • 18,937
  • 5
  • 45
  • 64
  • Thanks mmlooloo, but If i'll use this code draw circle by base canvas get hide.This is I want. Canvas c1 = new Canvas(); Canvas c2 = new Canvas(); So on c1 I wants to draw color and few Images and on c2 I wants to place image which will get refreshed time to time. So I don't want to touch my c1 which already has few content and wants to refresh always c2. how to do this? – Arpana Aug 23 '14 at 06:58
  • how can i understand these assumptions from your question? this is completely new question. i must go out now, but i think you can use background for static part and bitmap with transparent background for non static if you want to get help quickly ask your question. i think my answer to your question is correct and you should accept it if you consider just your `question assumption`. – mmlooloo Aug 23 '14 at 07:05
2

Try this:

You need to set the Paint style to stroke if you just want an outline with no fill:

Paint p = new Paint();
p.setStyle(Paint.Style.STROKE);

and if you want filled circle then:

Paint p = new Paint();
p.setStyle(Paint.Style.FILL);

Or you can refer this: http://android-coding.blogspot.in/2012/04/draw-circle-on-canvas-canvasdrawcirclet.html

Krupa Patel
  • 3,309
  • 3
  • 23
  • 28
  • Thanks Krupa but its not helpful for me. – Arpana Aug 23 '14 at 06:50
  • Other than this what you want?? – Krupa Patel Aug 23 '14 at 06:51
  • This is I want. Canvas c1 = new Canvas(); Canvas c2 = new Canvas(); So on c1 I wants to draw color and few Images and on c2 I wants to place image which will get refreshed time to time. So I don't want to touch my c1 which already has few content and wants to refresh always c2. how to do this? – Arpana Aug 23 '14 at 06:53