0

我有一条线应该越长越细。问题是,当像素变薄时,您可以清楚地看到跳跃。有没有办法在 Android 上进行亚像素渲染/抗锯齿?

canvas.drawRect()采用浮点值,但它忽略了这些。这是代码:

@Override
protected void onDraw(Canvas canvas) {
    float width = getMeasuredWidth() / (float) getMeasuredHeight()  * getMinimumHeight();
    float left = (getMeasuredWidth() - width) / 2.0f;
    canvas.drawRect(left, 0, left + width, getMeasuredHeight(), paint);
    super.onDraw(canvas);
}

油漆对象已ANTI_ALIAS_FLAG启用并包含纯色。

这是默认行:

默认线路

这是它变得更长更薄的时候。它的侧面应该有一些抗锯齿,尽管使整个过渡看起来更平滑。

细线

4

1 回答 1

0

这似乎做得更好:

@Override
protected void onDraw(Canvas canvas) {
    float width = getMeasuredWidth() / (float) getMeasuredHeight()  * getMinimumHeight();
    float left = (getMeasuredWidth() - width) / 2.0f;
    paint.setStrokeWidth(width * getResources().getDisplayMetrics().density);
    canvas.drawLine(left, 0, left, getMeasuredHeight(), paint);
    super.onDraw(canvas);
}
于 2013-01-18T18:38:37.930 回答