- 在canvas中圖片旋轉的問題
-
在canvas中插入圖片,當點擊右箭頭時,圖片順時針旋轉90°,但是點擊時沒有效果,到底哪裡錯了,請各位老師指教,非常謝謝!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
無標題文檔
body{
background:black;
}
window.onload = function() {
var aInput = document.getElementsByName("input");
var oImg = document.getElementById("img1");
var yImg = new Image();
var iNow = 0;
yImg.onload = function() {
draw(oImg);
}
yImg.src = oImg.src;
function draw(obj) {
var oC = document.createElement("canvas");
var oGC = oC.getContext('2d');
oC.width = obj.width;
oC.height = obj.height;
obj.parentNode.replaceChild(oC,obj);
oGC.drawImage(obj,0,0);
aInput[1].onclick = function() {
iNow++;
toChange();
}
function toChange() {
switch(iNow) {
case 1:
oC.width = obj.height;
oC.height = obj.width;
oGC.rotate(90*Math.PI/180);
oGC.drawImage(obj,0,-obj.height);
break;
}
}
}
}
最佳回答:
http://www.jb51.net/article/65323.htm