# CanvasDemo **Repository Path**: lemontwist/CanvasDemo ## Basic Information - **Project Name**: CanvasDemo - **Description**: Android中Canvas的使用详解 - **Primary Language**: Kotlin - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-04-16 - **Last Updated**: 2021-12-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: Android ## README # CanvasDemo #### 介绍 Android中Canvas的使用详解 #### 前言 Android中,如果我们想绘制复杂的自定义View或游戏,我们就需要熟悉绘图API。Android通过Canvas类暴露了很多drawXXX方法, 我们可以通过这些方法绘制各种各样的图形。Canvas绘图有三个基本要素:Canvas、绘图坐标系以及Paint。 Canvas是画布,我们通过Canvas的各种drawXXX方法将图形绘制到Canvas上面,在drawXXX方法中我们需要传入要绘制的图形的坐标形状,还要传入一个画笔Paint。 drawXXX方法以及传入其中的坐标决定了要绘制的图形的形状,比如drawCircle方法,用来绘制圆形,需要我们传入圆心的x和y坐标,以及圆的半径。 drawXXX方法中传入的画笔Paint决定了绘制的图形的一些外观,比如是绘制的图形的颜色,再比如是绘制圆面还是圆的轮廓线等。 Android系统的设计吸收了很多已有系统的诸多优秀之处,比如Canvas绘图。Canvas不是Android所特有的,Flex和Silverlight都支持Canvas绘图, Canvas也是HTML5标准中的一部分,主流的现代浏览器都支持用JavaScript在Canvas上绘图,如果你用过HTML5中的Canvas,你会发现Android的Canvas的绘图API与其很相似。 总之,Canvas绘图不是Android所特有的。 #### Canvas函数说明 1. `drawCircle` ``` /** * Draw the specified circle using the specified paint. If radius is 小于等于 0, then nothing will be * drawn. The circle will be filled or framed based on the Style in the paint. * * @param cx The x-coordinate of the center of the circle to be drawn * @param cy The y-coordinate of the center of the circle to be drawn * @param radius The radius of the circle to be drawn * @param paint The paint used to draw the circle */ public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint) { super.drawCircle(cx, cy, radius, paint); } ``` 2. xxxx 3. xxxx #### 绘制实例 1. 圆,CircleView 2. 矩形,RectangleView 3. 曲线,PathView 4. 曲线,PathView 5. 水柱效果,WaterColumnView 5. 绘制图片,BitmapView #### 参与贡献 1. https://blog.csdn.net/iispring/article/details/49770651