HTML5キャンバスの画像の背景の上に線を描こうとしています。 しかし、常に画像の後ろに線が引かれます。実際には、線が最初に描画され、次にピクチャが描画されます - 関数をどのように呼び出すかに関係なくHTML5キャンバス - 画像の背景に線を描くにはどうすればいいですか?
どのようにイメージの上に線を表示しますか?
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
drawbackground(canvas, context);
drawlines(canvas, context);
function drawbackground(canvas, context){
var imagePaper = new Image();
imagePaper.onload = function(){
context.drawImage(imagePaper,100, 20, 500,500);
};
imagePaper.src = "images/main_timerand3papers.png";
}
function drawlines(canvas, context){
context.beginPath();
context.moveTo(188, 130);
context.bezierCurveTo(140, 10, 388, 10, 388, 170);
context.lineWidth = 10;
// line color
context.strokeStyle = "black";
context.stroke();
}
最後の行はdrawbackgroundれるべき(キャンバス、コンテキスト、drawlines(キャンバス、コンテキスト)); ? –
いいえ、その場合は、メソッドdrawlinesを呼び出して、その戻り値をパラメータとして使用することになります。 – Chango
ありがとう!出来た 。 –