android 斜线 绘制_Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形) ....
时间: 2023-07-04 18:13:37 浏览: 282
要在 Android 中绘制斜线,可以使用 Canvas 对象的 drawLine() 方法。该方法需要四个参数:起点的坐标和终点的坐标。下面是一个示例代码:
```
// 创建一个 Bitmap 对象
Bitmap bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
// 创建一个 Canvas 对象并将其附加到 Bitmap 对象上
Canvas canvas = new Canvas(bitmap);
// 设置画笔的颜色和宽度
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStrokeWidth(5);
// 绘制斜线
canvas.drawLine(0, 0, 400, 400, paint);
// 将 Bitmap 对象显示在 ImageView 中
imageView.setImageBitmap(bitmap);
```
在上面的代码中,我们首先创建了一个 Bitmap 对象和一个 Canvas 对象,并将其附加到 Bitmap 对象上。然后,我们创建一个画笔对象,设置其颜色和宽度,并使用 drawLine() 方法绘制一条斜线。最后,我们将 Bitmap 对象显示在一个 ImageView 中。
除了 drawLine() 方法,Canvas 对象还提供了许多其他绘制图形的方法,如 drawArc()、drawCircle()、drawText()、drawRect() 等。您可以根据自己的需要选择适当的方法来绘制所需的图形。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)
![html](https://img-home.csdnimg.cn/images/20241231044918.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)