代码中包含的图像不会在画布上呈现。如果我使用任何其他风景图像,它的工作完全正常。我做错了什么?
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var image = document.createElement("img");
image.onload = function(){
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image,0,0);
}
image.src = "http://org.school66.group.us.west.2.s3.amazonaws.com/church.jpg"
// this image works perfectly fine
// http://org.school66.group.us.west.2.s3.amazonaws.com/bookclub.jpg

<canvas id="canvas"></canvas><br>
<button id="clockwise">Rotate right</button>
<button id="counterclockwise">Rotate left</button>
&#13;
答案 0 :(得分:0)
就像这样:
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var img = new Image();
img.onload = function() {
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(img,0,0);
};
img.src = "http://org.school66.group.us.west.2.s3.amazonaws.com/church.jpg";