这是我的 javascript 代码:
> var logoImg = new Image();
> logoImg.src = '../img/smiley.png';
>
> // Store the original width value so that we can keep the same width/height ratio later
> var originalWidth = logoImg.width;
>
> // Compute the new width and height values
> logoImg.width = Math.round((50 * document.body.clientWidth) / 100);
> logoImg.height = Math.round((logoImg.width * logoImg.height) / originalWidth);
>
> // Create an small utility object
> var logo = {
img : logoImg,
> x : (canvas.width / 2) - (logoImg.width / 2),
> y : (canvas.height / 2) - (logoImg.height / 2)
> }
>
> // Present the image
> c.drawImage(logo.img, logo.x, logo.y, logo.img.width, logo.img.height);
此代码不起作用图像未显示....我尝试跟踪代码,发现logoImg.width=0 和logoImg.height=0 ...有什么建议吗??????提前致谢