这是一个在画布元素上绘制一条线,然后在其上渲染两个图像的示例。
Ignacio 是正确的,但是您会遇到浏览器问题,因为我不相信 IE < 9 支持画布。
<html>
<head>
<style type="text/css">
canvas {
width: 600;
height: 200;
}
</style>
</head>
<body>
<canvas id="canvas">
</canvas>
<script type="text/javascript">
(function () {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var i = new Image();
i.src = 'https://www.balancedpayments.com/images/balanced.png';
i.onload = function () { ctx.drawImage(i, 100 - i.width / 2, 100 - i.height / 2); };
var j = new Image();
j.src = 'https://www.balancedpayments.com/images/balanced.png';
j.onload = function () { ctx.drawImage(j, 300 - i.width / 2, 100 - i.height / 2); };
ctx.beginPath();
ctx.moveTo(100, 100);
ctx.lineTo(500, 100);
ctx.stroke();
})();
</script>
</body>
</html>