无法在位图上绘制圆圈?

时间:2011-05-22 14:57:43

标签: android

我能够显示位图,但是我正在绘制的圆圈不会显示。我不确定我错过了什么。

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);
}

1 个答案:

答案 0 :(得分:5)

您的代码不是在位图上绘图,而是将您的位图绘制到画布中,然后在该画布的位图上绘制一个圆圈。结果然后扔掉了。然后,将原始位图(未更改)设置为ImageView。

您需要使用位图创建画布。然后绘制方法将绘制您的位图。

    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);