Codice HTML:
<canvas id="canvas-multiimge" width="450" height="150" src1="img1.png" src2="img2.bmp" src3="img3.bmp"></canvas>
<script>
var test=test||{};
test.LoadMultiImg= function(objId,newValue) {
var canvas = document.getElementById(objId);
var imgage1 = canvas.getAttribute("src1");
var imgage2 = canvas.getAttribute("src2");
var imgage3 = canvas.getAttribute("src3");
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
var w=canvas.width;
var h=canvas.height;
var wh= w>h?h:w;
var img1 = new Image();
img1.onload = function() {
ctx.drawImage(img1, 0,0, img1.width,img1.height, 0,0, w/3,h);
ctx.fillStyle = "rgba(0, 0, 0, 0)";
ctx.fillRect(0,0,w,h);
};
img1.src = imgage1;
var img2 = new Image();
img2.onload = function() {
ctx.drawImage(img2, 0,0, img2.width,img2.height, w/3,0, w/3,h);
ctx.fillStyle = "rgba(0, 0, 0, 0)";
ctx.fillRect(0,0,w,h);
};
img2.src = imgage2;
var img3 = new Image();
img3.onload = function() {
ctx.drawImage(img3, 0,0, img3.width,img3.height, w/3*2,0, w/3,h);
ctx.fillStyle = "rgba(0, 0, 0, 0)";
ctx.fillRect(0,0,w,h);
};
img3.src = imgage3;
};
test.LoadMultiImg('canvas-multiimge');
</script>
Cordiali saluti.