0
我正在繪製HTML5(畫布)應用程序,它的工作正常,除此之外,您繪製的圖形有點「鋸齒」,並不像我想要的那樣光滑。以下是代碼;這裏有什麼問題?用畫布繪製得到「鋸齒」
$(function() {
var letsdraw = false;
var theCanvas = document.getElementById('paint');
var ctx = theCanvas.getContext('2d');
theCanvas.width = 420;
theCanvas.height = 300;
var canvasOffset = $('#paint').offset();
$('#paint').mousemove(function(e) {
if (letsdraw === true) {
ctx.lineTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
ctx.stroke();
}
});
$('#paint').mousedown(function() {
letsdraw = true;
ctx.strokeStyle = 'blue';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
});
$(window).mouseup(function() {
letsdraw = false;
});
});
的可能重複[繪圖好看(如閃存)上粗帆布(HTML5)線 - 可能( http://stackoverflow.com/questions/4179069/drawing-good-looking-like-in-flash-lines-on-canvas-html5-possible) – JJJ 2012-01-07 15:32:38
不,我不會稱之爲重複。您在網上看到的畫布繪製應用程序比我的要平滑得多。實際上我的代碼有些問題,我不打算讓它比一般的更好。 – holyredbeard 2012-01-07 15:38:05