Android的像素渲染 [英] Android subpixel rendering

查看:232
本文介绍了Android的像素渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条线,应该得到更薄它得到了更长的时间。问题是,你可以清楚地看到一个跳跃时,得到一个像素更薄。有没有办法做到像素渲染/反锯齿在Android?

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/antialiasing on Android?

canvas.drawRect()接受浮点值,但它忽略那些。这里的code:

canvas.drawRect() takes float values, but it's ignoring those. Here's the code:

@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 启用,包含纯色。

这是默认的行:

这是当它变得更长和更薄。它应该有对双方的一些抗锯齿,虽然使整个过渡更加平滑似乎

This is when it gets longer and thinner. It should have some anti aliasing on the sides, though to make the whole transition seems smoother.

推荐答案

这似乎做得更好:

@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);
}

这篇关于Android的像素渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆