Flutter 画笔(Paint)、绘制直线(drawLine)(1),一个Android程序员的腾讯面试心得

这篇博客详细介绍了在Flutter中使用CustomPainter进行绘图时,如何设置`isAntiAlias`以消除锯齿,调整`strokeWidth`控制线条宽度,以及使用`StrokeCap`参数实现buff、round、square三种端点样式。通过示例代码展示了不同参数组合的效果,是Flutter开发者提升图形绘制能力的好资料。
摘要由CSDN通过智能技术生成

//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true

@override

bool shouldRepaint(CustomPainter oldDelegate) => true;

}

   

class MyPainter extends CustomPainter {

@override

void paint(Canvas canvas, Size size) {

//画背景

var paint = Paint()

…isAntiAlias = false

…strokeWidth=30.0

…color = Colors.red;

canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,60.0), paint…strokeCap);

}

//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true

@override

bool shouldRepaint(CustomPainter oldDelegate) => true;

}

class MyPainter extends CustomPainter {

@override

void paint(Canvas canvas, Size size) {

//画背景

var paint = Paint()

…isAntiAlias = false

…strokeWidth=30.0

…color = Colors.red;

canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,70.0), paint…strokeCap);

}

//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true

@override

bool shouldRepaint(CustomPainter oldDelegate) => true;

}

isAntiAlias=true(消除锯齿)

    

class MyPainter extends CustomPainter {

@override

void paint(Canvas canvas, Size size) {

//画背景

var paint = Paint()

…isAntiAlias = true

…strokeWidth=30.0

…color = Colors.red;

canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,60.0), paint…strokeCap);

}

//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true

@override

bool shouldRepaint(CustomPainter oldDelegate) => true;

}

class MyPainter extends CustomPainter {

@override

void paint(Canvas canvas, Size size) {

//画背景

var paint = Paint()

…isAntiAlias = true

…strokeWidth=30.0

…color = Colors.red;

canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,70.0), paint…strokeCap);

}

//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true

@override

bool shouldRepaint(CustomPainter oldDelegate) => true;

}

strokeWidth(画笔宽度)

class MyPainter extends CustomPainter {

@override

void paint(Canvas canvas, Size size) {

//画背景

var paint = Paint()

…isAntiAlias = true

…color = Colors.red;

canvas.drawLine(Offset(50.0, 46.0), Offset(200.0,46.0), paint…strokeCap…strokeWidth=4.0);

canvas.drawLine(Offset(50.0, 60.0), Offset(200.0,60.0), paint…strokeCap…strokeWidth=8.0);

canvas.drawLine(Offset(50.0, 80.0), Offset(200.0,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值