Flutter Canvas Paint类提供了很多属性

6 min read

Paint类提供了很多属性,上面只是一些常用属性,下面介绍它的所有属性

  • isAntiAlias: 是否抗锯齿
  • color: 画笔颜色
  • strokeWidth: 画笔宽度
  • style: 样式
    • PaintingStyle.fill 默认 填充
    • PaintingStyle.stroke 线
  • strokeCap: 定义画笔端点形状
    • StrokeCap.butt 无形状(默认)
    • StrokeCap.round 圆形
    • StrokeCap.square 正方形
  • strokeJoin: 定义线段交接时的形状
    1. StrokeJoin.miter 默认,当两条线段夹角小于30°时,StrokeJoin.miter将会变成StrokeJoin.bevel
    2. StrokeJoin.bevel
    3. StrokeJoin.round

strokeMiterLimit: 当strokeJoin为StrokeJoin.miter时且style为PaintingStyle.stroke有效,用来设置连接线的长度,一般可用strokeJoin来替换

imageFilter: 设置模糊度

ImageFilter.blur({double sigmaX = 0.0, double sigmaY = 0.0, TileMode tileMode = TileMode.clamp}): sigmaX与sigmaY在0~10之间,数值越大越模糊

ImageFilter.matrix 使用matrix来创建模糊度

ImageFilter.compose 组合两个ImageFilter

invertColors: 反转画笔颜色(跟设置的color有关)

blendMode: 混合模式,两个形状混合时使用的模式,具体可参考blendMode,默认为BlendMode.srcOver

shader: 着色器

maskFilter: 模糊蒙版滤镜,比如绘制一些阴影效果或者艺术字等

filterQuality: 设置滤镜(如maskFilter或者image)的质量

colorFilter: 彩色矩阵滤色器,可以通过设置此属性改变画笔颜色如黑白色