flutter定制更好的抗质量

发布于 2025-01-30 20:25:28 字数 5327 浏览 4 评论 0原文

paint.isantialias = false;

paint.isantialias = true;

@override
  void paint(Canvas canvas, Size size) {
    final Path path_0 = Path();
    path_0.moveTo(
      size.width * 0.5002533,
      size.height * 0.004880920,
    );
    path_0.cubicTo(
      size.width * 0.2252237,
      size.height * 0.004880922,
      size.width * 0.002532500,
      size.height * 0.2268787,
      size.width * 0.002532500,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.002532500,
      size.height * 0.7752251,
      size.width * 0.2252237,
      size.height * 0.9972229,
      size.width * 0.5002533,
      size.height * 0.9972220,
    );
    path_0.cubicTo(
      size.width * 0.7752828,
      size.height * 0.9972229,
      size.width * 0.9979740,
      size.height * 0.7752251,
      size.width * 0.9979740,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.9979740,
      size.height * 0.2268787,
      size.width * 0.7752828,
      size.height * 0.004880922,
      size.width * 0.5002533,
      size.height * 0.004880920,
    );
    path_0.close();
    path_0.moveTo(
      size.width * 0.5002533,
      size.height * 0.8731800,
    );
    path_0.cubicTo(
      size.width * 0.3693230,
      size.height * 0.8731802,
      size.width * 0.2513929,
      size.height * 0.7020954,
      size.width * 0.2513929,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.2513929,
      size.height * 0.3000084,
      size.width * 0.3692386,
      size.height * 0.1289237,
      size.width * 0.5002533,
      size.height * 0.1289230,
    );
    path_0.cubicTo(
      size.width * 0.6312679,
      size.height * 0.1289237,
      size.width * 0.7491136,
      size.height * 0.3000084,
      size.width * 0.7491136,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.7491136,
      size.height * 0.7020954,
      size.width * 0.6311835,
      size.height * 0.8731802,
      size.width * 0.5002533,
      size.height * 0.8731800,
    );
    path_0.close();

    final Paint paint0Fill = Paint()..style = PaintingStyle.fill;
    paint0Fill.color = colors['kMainColor']!;
    canvas.drawPath(path_0, paint0Fill);

    final Path path_1 = Path();
    path_1.moveTo(
      size.width * 0.8129326,
      size.height * 0.1151220,
    );
    path_1.cubicTo(
      size.width * 0.7594125,
      size.height * 0.07859968,
      size.width * 0.6966064,
      size.height * 0.05444753,
      size.width * 0.6312679,
      size.height * 0.05444750,
    );
    path_1.cubicTo(
      size.width * 0.5330069,
      size.height * 0.05444753,
      size.width * 0.4440317,
      size.height * 0.1035934,
      size.width * 0.3782711,
      size.height * 0.1804250,
    );
    path_1.cubicTo(
      size.width * 0.4149924,
      size.height * 0.1479424,
      size.width * 0.4568631,
      size.height * 0.1288395,
      size.width * 0.5002533,
      size.height * 0.1288390,
    );
    path_1.cubicTo(
      size.width * 0.6311835,
      size.height * 0.1288395,
      size.width * 0.7491136,
      size.height * 0.2999243,
      size.width * 0.7491136,
      size.height * 0.5009670,
    );
    path_1.cubicTo(
      size.width * 0.7491136,
      size.height * 0.7020113,
      size.width * 0.6312679,
      size.height * 0.8730960,
      size.width * 0.5002533,
      size.height * 0.8730960,
    );
    path_1.cubicTo(
      size.width * 0.4568631,
      size.height * 0.8730960,
      size.width * 0.4149924,
      size.height * 0.8539931,
      size.width * 0.3782711,
      size.height * 0.8215090,
    );
    path_1.cubicTo(
      size.width * 0.4440317,
      size.height * 0.8984263,
      size.width * 0.5330069,
      size.height * 0.9474880,
      size.width * 0.6312679,
      size.height * 0.9474880,
    );
    path_1.cubicTo(
      size.width * 0.6966064,
      size.height * 0.9474880,
      size.width * 0.7594125,
      size.height * 0.9233359,
      size.width * 0.8129326,
      size.height * 0.8868970,
    );
    path_1.cubicTo(
      size.width * 0.9257977,
      size.height * 0.7960111,
      size.width * 0.9979740,
      size.height * 0.6569890,
      size.width * 0.9979740,
      size.height * 0.5009670,
    );
    path_1.cubicTo(
      size.width * 0.9979740,
      size.height * 0.3450307,
      size.width * 0.9257133,
      size.height * 0.2060927,
      size.width * 0.8129326,
      size.height * 0.1151220,
    );
    path_1.close();

    final Paint paint1Fill = Paint()..style = PaintingStyle.fill;
    paint1Fill.color = AppTheme.darken(colors['kMainColor']!);
    canvas.drawPath(path_1, paint1Fill);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }

有什么办法可以更好地走到tialias帆布路径(不是图像)?如果是图像,我会使用过滤器,但不是图像。我认为这是可能的。

的定制版中

a>,但没有找到一种在Flutter “> ”在此处输入图像说明”

Paint.isAntiAlias = false;

enter image description here

Paint.isAntiAlias = true;

enter image description here

@override
  void paint(Canvas canvas, Size size) {
    final Path path_0 = Path();
    path_0.moveTo(
      size.width * 0.5002533,
      size.height * 0.004880920,
    );
    path_0.cubicTo(
      size.width * 0.2252237,
      size.height * 0.004880922,
      size.width * 0.002532500,
      size.height * 0.2268787,
      size.width * 0.002532500,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.002532500,
      size.height * 0.7752251,
      size.width * 0.2252237,
      size.height * 0.9972229,
      size.width * 0.5002533,
      size.height * 0.9972220,
    );
    path_0.cubicTo(
      size.width * 0.7752828,
      size.height * 0.9972229,
      size.width * 0.9979740,
      size.height * 0.7752251,
      size.width * 0.9979740,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.9979740,
      size.height * 0.2268787,
      size.width * 0.7752828,
      size.height * 0.004880922,
      size.width * 0.5002533,
      size.height * 0.004880920,
    );
    path_0.close();
    path_0.moveTo(
      size.width * 0.5002533,
      size.height * 0.8731800,
    );
    path_0.cubicTo(
      size.width * 0.3693230,
      size.height * 0.8731802,
      size.width * 0.2513929,
      size.height * 0.7020954,
      size.width * 0.2513929,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.2513929,
      size.height * 0.3000084,
      size.width * 0.3692386,
      size.height * 0.1289237,
      size.width * 0.5002533,
      size.height * 0.1289230,
    );
    path_0.cubicTo(
      size.width * 0.6312679,
      size.height * 0.1289237,
      size.width * 0.7491136,
      size.height * 0.3000084,
      size.width * 0.7491136,
      size.height * 0.5010510,
    );
    path_0.cubicTo(
      size.width * 0.7491136,
      size.height * 0.7020954,
      size.width * 0.6311835,
      size.height * 0.8731802,
      size.width * 0.5002533,
      size.height * 0.8731800,
    );
    path_0.close();

    final Paint paint0Fill = Paint()..style = PaintingStyle.fill;
    paint0Fill.color = colors['kMainColor']!;
    canvas.drawPath(path_0, paint0Fill);

    final Path path_1 = Path();
    path_1.moveTo(
      size.width * 0.8129326,
      size.height * 0.1151220,
    );
    path_1.cubicTo(
      size.width * 0.7594125,
      size.height * 0.07859968,
      size.width * 0.6966064,
      size.height * 0.05444753,
      size.width * 0.6312679,
      size.height * 0.05444750,
    );
    path_1.cubicTo(
      size.width * 0.5330069,
      size.height * 0.05444753,
      size.width * 0.4440317,
      size.height * 0.1035934,
      size.width * 0.3782711,
      size.height * 0.1804250,
    );
    path_1.cubicTo(
      size.width * 0.4149924,
      size.height * 0.1479424,
      size.width * 0.4568631,
      size.height * 0.1288395,
      size.width * 0.5002533,
      size.height * 0.1288390,
    );
    path_1.cubicTo(
      size.width * 0.6311835,
      size.height * 0.1288395,
      size.width * 0.7491136,
      size.height * 0.2999243,
      size.width * 0.7491136,
      size.height * 0.5009670,
    );
    path_1.cubicTo(
      size.width * 0.7491136,
      size.height * 0.7020113,
      size.width * 0.6312679,
      size.height * 0.8730960,
      size.width * 0.5002533,
      size.height * 0.8730960,
    );
    path_1.cubicTo(
      size.width * 0.4568631,
      size.height * 0.8730960,
      size.width * 0.4149924,
      size.height * 0.8539931,
      size.width * 0.3782711,
      size.height * 0.8215090,
    );
    path_1.cubicTo(
      size.width * 0.4440317,
      size.height * 0.8984263,
      size.width * 0.5330069,
      size.height * 0.9474880,
      size.width * 0.6312679,
      size.height * 0.9474880,
    );
    path_1.cubicTo(
      size.width * 0.6966064,
      size.height * 0.9474880,
      size.width * 0.7594125,
      size.height * 0.9233359,
      size.width * 0.8129326,
      size.height * 0.8868970,
    );
    path_1.cubicTo(
      size.width * 0.9257977,
      size.height * 0.7960111,
      size.width * 0.9979740,
      size.height * 0.6569890,
      size.width * 0.9979740,
      size.height * 0.5009670,
    );
    path_1.cubicTo(
      size.width * 0.9979740,
      size.height * 0.3450307,
      size.width * 0.9257133,
      size.height * 0.2060927,
      size.width * 0.8129326,
      size.height * 0.1151220,
    );
    path_1.close();

    final Paint paint1Fill = Paint()..style = PaintingStyle.fill;
    paint1Fill.color = AppTheme.darken(colors['kMainColor']!);
    canvas.drawPath(path_1, paint1Fill);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }

Is there any way to antialias canvas path(not image) better? If it was an image i'd use filterQuality but it's not an image. I think this should be possible.

Read article about this thing on Android, but did not find a way to use bitmap in Flutter's CustomPaint

I expect to get a result that looks like this:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文