Android subpixel rendering

后端 未结 1 1112
天涯浪人
天涯浪人 2021-01-26 08:04

I have a line that should get thinner the longer it gets. The problem is, that you can clearly see a jump when it gets a pixel thinner. Is there a way to do subpixel rendering/a

相关标签:
1条回答
  • 2021-01-26 08:54

    This seems to do a better job:

    @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);
    }
    
    0 讨论(0)
提交回复
热议问题