【问题标题】:Can I draw with antialiasing on canvas?我可以在画布上使用抗锯齿进行绘制吗?
【发布时间】:2012-05-14 23:08:02
【问题描述】:

我可以在画布上使用抗锯齿进行绘制吗?

我需要我的圆圈和线条边缘光滑。

【问题讨论】:

    标签: android graphics android-canvas antialiasing


    【解决方案1】:

    绘图操作需要Paint。在这个Paint 你设置Paint.setFlags(Paint.ANTI_ALIAS_FLAG)

    【讨论】:

    • 您可以改用 mPaint.setAntiAlias(true);,正如 Arun Chettoor 建议的那样
    【解决方案2】:

    看看这个。它相当使用光滑的边缘.. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html

    获得抗锯齿所需的绘制属性是:

         mPaint = new Paint();
         mPaint.setAntiAlias(true);
    

    作图用途:

         mPath = new Path();
         mPath.reset();
         mPath.moveTo(x, y);//can be used where to trigger the path
    

    onDraw 方法应包含:

         canvas.drawPath(mPath, mPaint);
    

    将 mPath 和 mPaint 声明为全局。

    【讨论】:

      【解决方案3】:

      您可以在 Paint 构造函数 Paint(int) 中提供 ANTI_ALIAS_FLAG . ANTI_ALIAS_FLAG 标志在绘图时启用抗锯齿。启用此标志将导致所有支持抗锯齿的绘制操作都使用它。

      或者您可以稍后使用 setFlags(int) 方法设置此标志

      Kotlin 中的示例实现:

       //Paint
      private var indicatorPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
          isAntiAlias = true
          color = fillColor
          strokeWidth = lineThickness.toFloat()
          style = Paint.Style.STROKE
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-04
        • 2013-10-03
        • 2011-08-27
        • 2011-07-12
        • 2010-12-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多