<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                正統的HTML5 Canvas中如下代碼 ~~~ ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(10, 100); ctx.lineTo(300,100); ctx.stroke(); ~~~ 運行結果繪制出來的并不是一個像素寬度的線 ![](https://box.kancloud.cn/2016-05-17_573adb37d81c9.jpg) 感覺怎么好粗啊,跟常常見到的網頁版各種繪制線效果很不一樣,難道HTML5 Canvas就沒想到搞好點嘛其實這個根本原因在于Canvas的繪制不是從中間開始的而是從0~1,不是從0.5~1 + 0~0.5的繪制方式,所以導致fade在邊緣,看上去線很寬。 解決方法有兩個,一個是錯位覆蓋法,另外一種是中心平移(0.5,0.5)。實現代碼如下: 錯位覆蓋法我已經包裝成一個原始context的函數 ~~~ /** * <p> draw one pixel line </p> * @param fromX * @param formY * @param toX * @param toY * @param backgroundColor - default is white * @param vertical - boolean */ CanvasRenderingContext2D.prototype.onePixelLineTo = function(fromX, fromY, toX, toY, backgroundColor, vertical) { var currentStrokeStyle = this.strokeStyle; this.beginPath(); this.moveTo(fromX, fromY); this.lineTo(toX, toY); this.closePath(); this.lineWidth=2; this.stroke(); this.beginPath(); if(vertical) { this.moveTo(fromX+1, fromY); this.lineTo(toX+1, toY); } else { this.moveTo(fromX, fromY+1); this.lineTo(toX, toY+1); } this.closePath(); this.lineWidth=2; this.strokeStyle=backgroundColor; this.stroke(); this.strokeStyle = currentStrokeStyle; }; ~~~ 中心平移法代碼如下: ~~~ ctx.save(); ctx.translate(0.5,0.5); ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(10, 100); ctx.lineTo(300,100); ctx.stroke(); ctx.restore(); ~~~ 要特別注意確保你的所有坐標點是整數,否則HTML5會自動實現邊緣反鋸齒 又導致你的一個像素直線看上去變粗了。 運行效果: ![](https://box.kancloud.cn/2016-05-17_573adb37ea9f1.jpg) 現在效果怎么樣,這個就是HTML5 Canvas畫線的一個小技巧覺得不錯請頂一下。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看