绘制线小于一个像素厚度需要Android 4.2中的反锯齿 [英] Drawing line less than one pixel thick requires anti-aliasing in Android 4.2

查看:243
本文介绍了绘制线小于一个像素厚度需要Android 4.2中的反锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android中绘制一条非常细的线(小于一个像素的厚度)。我使用

I'm trying to draw a very thin line (less than one pixel thick) in android. I'm using

Paint blackThin = new Paint();
blackThin.setStrokeWidth(0.1f);
blackThin.setColor(Color.BLACK);

以初始化绘画对象。

这在Android 2.2中工作正常,但是当我在4.2(也是4.1,我认为 - 我测试了一个简单 - 我没有测试任何其他版本,除了2.2,4.1.2和4.2)线路不会出现在我画它们。为了使它们出现在4.2,看起来像我必须设置反锯齿标志为真。 (我试过,线路出现了。)但是我真的不想要,因为它模糊线条等。

This works fine in Android 2.2, but when I try it in 4.2 (also 4.1, I think - I tested that one briefly - I haven't tested any other versions other that 2.2, 4.1.2 and 4.2) the lines won't show up when I draw them. To make them show up in 4.2, it seems like I have to set the anti-aliasing flag to be true. (I tried that, and the lines showed up.) But I really don't want that, because that blurs the lines and such.

这是Android中的一个错误?有没有什么我可以做,以使它工作除了打开反走样?

Is this a bug in Android? Is there something I can do to make it work other than turning on anti-aliasing?

编辑:我也测试了这个与像素大小0.9,问题是相同。

I also tested this with a pixel size of 0.9, and the problem is the same.

感谢您的帮助!

推荐答案

width 中画出的线不到抗锯齿的像素。

You can't draw lines less than a pixel in width without anti-aliasing.

反锯齿的全部是计算一个像素的颜色,如果一个元素没有完全填充像素(像一行只有十分之一像素的宽度)。

The whole point of anti-aliasing is to calculate what a pixel's colour would be, if a element doesn't completely fill the pixel (Like a line that's only a tenth of a pixel's width).

可以通过绘制一条较浅的线来稍微模拟它,但是仍然不会接近实际的抗锯齿线。

You could somewhat simulate it by drawing a lighter line, but that still wouldn't come close to a actually anti-aliased line.

看看这个图像,例如:

>

通过改变线条的颜色真的不可能复制抗锯齿的结果。

It's really not possible to replicate the anti-aliased result by changing the line's colour.

我实现了示例中的行宽度> 1个像素,但是相同的原理适用。作为用线填充多少像素的结果来计算像素的暗度。因此,灰色的实线不起作用。

I realise the lines in the example are > 1 pixel in width, but the same principle applies. The "darkness" of a pixel is calculated as a result of how much of the pixel is filled with the line. For that reason, a solid grey line won't work.

这篇关于绘制线小于一个像素厚度需要Android 4.2中的反锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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