我有一个具有百分比宽度和高度的画布,我正在那里绘制图像。
我想用画布的 50% 宽度和 100% 高度绘制图像。我该如何做到这一点?
这是一些代码:
#canvas {
width: 100%;
height: 33%;
}
var cv = document.getElementById('canvas');
var cx = cv.getContext('2d');
var bg = document.createElement('img');
bg.src = bg_url;
cx.drawImage(bg, ?, ?, ?, ?);
// cx.drawImage(bg, 0, 0, 50%, 100%); essentially
// now let's draw that second image at 50% of the canvas (tiling)
cx.drawImage(bg, ?, ?, ?, ?);
// cx.drawImage(bg, 50%, 0, 50%, 100%); essentially