| function rotate(obj,arr){ ... // 對現代瀏覽器寫入HTML5的元素進行旋轉: canvas }else{ var c = document.getElementById('canvas_'+obj); if(c== null){ img.style.visibility = 'hidden'; img.style.position = 'absolute'; c = document.createElement('canvas'); c.setAttribute("id",'canvas_'+obj); img.parentNode.appendChild(c); } var canvasContext = c.getContext('2d'); switch(n) { default : case 0 : c.setAttribute('width', img.width); c.setAttribute('height', img.height); canvasContext.rotate(0 * Math.PI / 180); canvasContext.drawImage(img, 0, 0); break; case 1 : c.setAttribute('width', img.height); c.setAttribute('height', img.width); canvasContext.rotate(90 * Math.PI / 180); canvasContext.drawImage(img, 0, -img.height); break; case 2 : c.setAttribute('width', img.width); c.setAttribute('height', img.height); canvasContext.rotate(180 * Math.PI / 180); canvasContext.drawImage(img, -img.width, -img.height); break; case 3 : c.setAttribute('width', img.height); c.setAttribute('height', img.width); canvasContext.rotate(270 * Math.PI / 180); canvasContext.drawImage(img, -img.width, 0); break; }; } } |