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