I'm trying to draw a circle on an image which placed as res/drawable/schoolboard.png
. the image fills the activity background. the following does not work:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.schoolboard);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(60, 50, 25, paint);
ImageView imageView = (ImageView)findViewById(R.drawable.schoolboard);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);
any help will be highly appreciated. thanks.
First of all you need to create a new bitmap, because bitmap from BitmapFactory.decodeResource() method is immutable. You can do this with the following code:
Use this bitmap in Canvas constructor. Then draw your bitmap on canvas.
Also R.drawable.schoolboard is not a correct view id.
There are some errors in your code: first of thing you cannot give reference Id for drawable in
findViewById
so I think you mean something like thatschoolboard_image_view
is the image id in your xml layout (check your layout for the right id)Please make sure to use the right image Id for:
ImageView imageView = (ImageView)findViewById(R.id.schoolboard_image_view);