0

Chrome 的 Canvas 实现中存在一个已知错误,其中对 lineTo 的连续调用有时会在角落放置像素:http: //jsfiddle.net/rPJBr/2/

var cx = document.getElementById('c').getContext('2d');
cx.beginPath();
cx.moveTo(200.5, 200.5);
cx.lineTo(200.5, 100.5);
cx.lineTo(100.5, 100.5);
cx.stroke();

这是win7上chrome 24上行为的图像和放大图

缺少角像素再现

该错误已记录在这里:http ://code.google.com/p/chromium/issues/detail?id=137465

此错误是否有已知的解决方法?

4

1 回答 1

0
if(windows.chrome) {
    var p = CanvasRenderingContext2D.prototype;
    p.origLineTo = p.lineTo;
    p.lineTo = function(x, y) {
        this.fillRect(x - 0.5, y - 0.5, 1, 1);
        return this.origLineTo(x, y);
    };
    p.origMoveTo = p.moveTo;
    p.moveTo = function(x, y) {
        this.fillRect(x - 0.5, y - 0.5, 1, 1);
        return this.origMoveTo(x, y);
    };
}
于 2013-06-26T19:20:43.167 回答