我能在画布上使用反锯齿来绘制吗?
我需要让我的圆和线条有平滑的边缘。
我能在画布上使用反锯齿来绘制吗?
我需要让我的圆和线条有平滑的边缘。
绘制操作需要使用Paint
。在这个Paint
中,您可以设置 Paint.setFlags(Paint.ANTI_ALIAS_FLAG)
属性。
看这个。它使用了平滑边缘。 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(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
}
mPaint.setAntiAlias(true);
,正如Arun Chettoor所建议的那样。 - Maksim Turaev