android
android canvas类中常用的方法有绘制基本图形、绘制路径、绘制文本、绘制图像、处理颜色和样式、处理矩阵、绘制阴影等等。详细介绍
1、绘制基本图形drawRect绘制矩形;drawRoundRect绘制圆角矩形;drawCircle绘制圆形;drawOval绘制椭圆;drawLine绘制直线;drawPath绘制Path对象;
2、绘制路径方法等等。
android详细介绍
Android Canvas 类是用于绘制图形和处理图像的类,它位于 android.graphics 包中。Canvas 类提供了一系列的方法来绘制各种形状、路径、文本和图像,以及处理颜色、样式和矩阵等。以下是 Canvas 类中一些常用的方法
绘制基本图形
drawRect(RectF rect, Paint paint)绘制矩形。drawRoundRect(RectF rect, float rx, float ry, Paint paint)绘制圆角矩形。drawCircle(float x, float y, float radius, Paint paint)绘制圆形。drawOval(RectF oval, Paint paint)绘制椭圆。drawLine(float x1, float y1, float x2, float y2, Paint paint)绘制直线。drawPath(Path path, Paint paint)绘制 Path 对象。
绘制路径
drawPath(Path path, Paint paint)绘制 Path 对象。drawPath(Path path, Paint paint, PathEffect pathEffect)绘制 Path 对象,并应用 PathEffect。drawRect(RectF rect, Paint paint, Path path)在给定的矩形区域内绘制 Path。
绘制文本
drawText(CharSequence text, float x, float y, Paint paint)在指定位置绘制文本。drawText(CharSequence text, float x, float y, Paint paint, Paint.Align align)在指定位置绘制文本,并指定文本对齐方式。drawTextonPath(CharSequence text, Path path, float hAlign, float vAlign, Paint paint)在给定路径上绘制文本。
绘制图像
drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)绘制 Bitmap 图像。drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint, Matrix matrix)绘制 Bitmap 图像,并应用矩阵变换。drawBitmap(Bitmap bitmap, float x, float y, Paint paint)在指定位置绘制 Bitmap 图像。drawBitmap(Bitmap bitmap, float x, float y, Paint paint, Matrix matrix)在指定位置绘制 Bitmap 图像,并应用矩阵变换。
处理颜色和样式
setColor(int color)设置画笔颜色。setStrokeWidth(float width)设置画笔宽度。setStyle(Paint.Style style)设置画笔样式(如实线、虚线等)。setAntiAlias(boolean aa)设置抗锯齿效果。setColorFilter(ColorFilter cf)设置颜色滤镜。
处理矩阵
setMatrix(Matrix matrix)设置当前矩阵。getMatrix(Matrix matrix)获取当前矩阵。translate(float dx, float dy)平移当前矩阵。scale(float scaleX, float scaleY)缩放当前矩阵。rotate(float degrees)旋转当前矩阵。skew(float sx, float sy)倾斜当前矩阵。
绘制阴影
drawRect(RectF rect, Paint paint, float radius)绘制带有阴影的矩形。drawRoundRect(RectF rect, float rx, float ry, Paint paint, float radius)绘制带有阴影的圆角矩形。
这只是 Canvas 类的一部分方法,实际上 Canvas 类提供了许多其他方法来处理不同的绘图任务。要了解更多关于 Canvas 类的方法,请参考 Android 官方文档https//developer.android.com/reference/android/graphics/Canvas