Android 无法在位图上绘制圆?
我可以显示位图,但我正在绘制的圆圈不显示。我不确定我错过了什么Android 无法在位图上绘制圆?,android,Android,我可以显示位图,但我正在绘制的圆圈不显示。我不确定我错过了什么 private void loadImage() { File f = new File(imagesPath, currImageName); Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath()); BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap); Pain
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);
}
代码不是在位图上绘制,而是将位图绘制到画布中,然后在画布的位图上绘制一个圆。结果就被扔掉了。然后将原始位图(未更改)设置到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);
谢谢,伙计,我很感激。