我想画一个很细的线(小于一个像素厚)的机器人。我使用的是
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);
初始化油漆对象。
to initialize the paint object.
这工作正常,在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.
感谢您的帮助!
您不能画线不到像素宽度
无抗锯齿。
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.