【发布时间】:2013-12-19 03:35:56
【问题描述】:
我想在我的 Android 应用程序的画布上画一个圆圈。我进行了很多搜索,并意识到如果我需要一种可以随时更新的动态绘画形式,我需要使用画布而不是 imageView。
感谢任何帮助
这是我到目前为止编写的代码,但它不会在 android 设备屏幕上绘制任何内容:
private void createBitMap() {
Bitmap bitMap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); //creates bmp
bitMap = bitMap.copy(bitMap.getConfig(), true); //lets bmp to be mutable
Canvas canvas = new Canvas(bitMap); //draw a canvas in defined bmp
Paint paint = new Paint(); //define paint and paint color
paint.setColor(Color.RED);
paint.setStyle(Style.FILL_AND_STROKE);
//paint.setAntiAlias(true);
canvas.drawCircle(50, 50, 10, paint);
}
【问题讨论】:
-
简单使用:protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(x, y, 半径, 油漆); }
标签: java android android-canvas draw geometry