2012-07-24 112 views
0

使用Android画布绘制命令:Android,线宽,像素尺寸

如果我设置stroke = 0或stroke = 1并绘制水平线,则线条像素为两个像素高。如果我设置stroke = 2,像素也是两个像素高但更亮。

如果我绘制单个像素,像素是一个2x2矩阵,笔画= 0或笔画= 1。如果笔画= 2,我也得到一个2x2矩阵,但有更明亮的像素。

我必须做些什么来获得只有一个像素高的线? 我必须做些什么才能获得只有一个像素的像素?

注意:正在使用的设备的屏幕尺寸为480 x 800或更大。

Paint thePaint = new Paint();     
thePaint.setARGB(a, r, g, b);       
thePaint.setAntiAlias(true); 
thePaint.setStyle(Paint.Style.FILL); 
thePaint.setStrokeWidth(0); 
canvas.drawLine(x1,y1,x2,y2, thePaint); 
+0

根据文档,strokeWidth为0应该是1像素,不管是什么......您能否提供一些代码来显示您如何创建Paint对象以及如何绘制到Canvas? – 2012-07-24 01:26:59

+0

已添加代码。是的,这就是文档所说的。这不是现实。 – Xarph 2012-07-24 03:09:59

回答

2

我与罗马盖伊@google沟通这个问题。他说除了设置stroke = 0之外,还需要关闭AntiAlias。我的测试表明他是正确的。 Google文档目前不反映这一要求。此代码有效。

Paint thePaint = new Paint();     
thePaint.setARGB(a, r, g, b);       
thePaint.setAntiAlias(false); 
thePaint.setStyle(Paint.Style.STROKE); 
thePaint.setStrokeWidth(0); 
canvas.drawLine(x1,y1,x2,y2, thePaint); 
+0

你可以接受你自己的正确答案。 – 2012-08-13 12:37:43

0

它看起来像你需要这个,而不是更换线

thePaint.setStyle(Paint.Style.FILL); 

thePaint.setStyle(Paint.Style.STROKE); 
+0

我已经试过了。没什么区别。 – Xarph 2012-07-25 22:53:29

+0

是你的x1,y1,x2,y2值的所有整数值吗?当您有小数值时,您可以获得有趣的锯齿。 – 2012-07-26 02:01:24