2011-05-22 191 views
2

我能夠顯示位圖,但我繪製的圓形不顯示。我不確定我錯過了什麼。無法在位圖上繪製圓圈?

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

回答

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

謝謝隊友,我很感激。 – Beorn 2011-05-22 15:47:26