Reputation: 21
I'm able to display the bitmap, but the circle in which I'm drawing doesn't display. I'm not sure what I'm missing.
private void loadImage() {
File f = new File(imagesPath, currImageName);
Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
canvas = new Canvas();
canvas.drawCircle(60, 50, 25, paint);
bitmapDrawable.draw(canvas);
ImageView imageView = (ImageView)findViewById(R.id.imageview);
imageView.setAdjustViewBounds(true);
imageView.setImageDrawable(bitmapDrawable);
}
Upvotes: 2
Views: 2394
Reputation: 6397
Your code is NOT drawing on the bitmap, rather is is drawing your bitmap into a canvas, then drawing a circle on that canvas's bitmap. The result is then thrown away. You then set your original bitmap (unaltered) into the ImageView.
You need to create the canvas with your bitmap. Then the draw method will draw on your bitmap.
Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
// create canvas to draw on the bitmap
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(60, 50, 25, paint);
ImageView imageView = (ImageView)findViewById(R.id.imageview);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);
Upvotes: 5