【发布时间】:2012-05-14 23:08:02
【问题描述】:
我可以在画布上使用抗锯齿进行绘制吗?
我需要我的圆圈和线条边缘光滑。
【问题讨论】:
标签: android graphics android-canvas antialiasing
我可以在画布上使用抗锯齿进行绘制吗?
我需要我的圆圈和线条边缘光滑。
【问题讨论】:
标签: android graphics android-canvas antialiasing
绘图操作需要Paint。在这个Paint 你设置Paint.setFlags(Paint.ANTI_ALIAS_FLAG)
【讨论】:
mPaint.setAntiAlias(true);,正如 Arun Chettoor 建议的那样
看看这个。它相当使用光滑的边缘.. 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 声明为全局。
【讨论】:
您可以在 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
}
【讨论】: