<p>I have extremely small canvas (32x16 pixels) and I want to draw a straight line (stroke width 1) from <code>0,0</code> to <code>32,0</code> such that no other <code>y</code> value has any color due to it.</p>
<p>I have tried <code>Go Graphics</code>, <code>draw2d</code> and some others but they all draw line with some <code>alpha</code> to it and the stroke width is not exactly 1 when saved as <code>BMP</code>.</p>
<p>The reason I want such feature is because I'll be displaying the <code>32x16</code> image on a display where each pixel is approx 1cm x 1cm.</p>
<p>Is there any package that allows drawing lines, circles and possibly render string without the issue mentioned above?</p>
<hr/>**评论:**<br/><br/>klauspost: <pre><p>Do you mean like this: <a href="https://play.golang.org/p/4nUUQrN4zyE" rel="nofollow">https://play.golang.org/p/4nUUQrN4zyE</a></p></pre>alyyousuf7: <pre><p>Yes</p></pre>Frakturfreund: <pre><p>You probably should use <a href="https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm" rel="nofollow">Bresenham's line algorithm</a> for this. A quick search shows that <a href="https://godoc.org/github.com/StephaneBunel/bresenham" rel="nofollow">there is already an implementation in Go</a>.</p></pre>alyyousuf7: <pre><p>Oh wow, heard about this algorithm for the first time, interesting.</p></pre>
![](https://static.golangjob.cn/static/img/banner.png)