How to draw straight line stroke without color bleeding to other pixels

xuanbao · · 469 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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&#39;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&#39;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>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

469 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传