1
我想從第一個畫布生成圖像,然後在另一個畫布中繪製,但是我遇到了問題,因爲我不知道爲什麼我沒有看到其他任何內容帆布。這是我的代碼:HTML將圖像從畫布複製到另一個畫布
<canvas id="gameCanvas" width="704" height="608" />
<script type='text/javascript'>
// prepaire our game canvas
var canvas = document.getElementById("gameCanvas");
var context = canvas.getContext("2d");
var ctx = document.createElement("canvas").getContext("2d");
ctx.canvas.width = 2048;
ctx.canvas.height = 2048;
var rows = 64;
var columns = 64;
this.image = new Image();
var imageObject = document.createElement("img");
var me = this;
/// need this as loading is async
imageObject.onload = function() {
for (var i = 0; i < rows; i++) {
for (var j=0; j <columns; j++) {
ctx.drawImage(this, i*32,j*32,32,32);
}
}
// store the generate map as this image texture
me.image.src = ctx.canvas.toDataURL("image/jpg");
}
imageObject.src='ground.jpg';
this.image.src = ctx.canvas.toDataURL("image/jpg");
context.drawImage(this.image, 0, 0, 300, 300, 0, 0, 300,300);
</script>
請諮詢爲什麼它不起作用?