2012-07-24 65 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