พลิก ‹canvas› (หมุน 180 องศา) หลังจากเผยแพร่บนหน้าแล้ว

ฉันกำลังพยายามหมุนองค์ประกอบ canvas หลังจากที่เพิ่มเข้ากับ DOM แล้ว Canvas มีขนาด 600x50 และนี่คือรหัสที่อยู่ในมือ:

var canvas = document.getElementsByTagName('canvas')[2];
var ctx = canvas.getContext('2d');
ctx.translate(300, 25); // rotate @ center

ctx.rotate(angle * Math.PI/180);

ซึ่งไม่บรรลุภารกิจ ฉันพลาดอะไรไปรึเปล่า?

ขอบคุณ


person smallmeans    schedule 14.04.2010    source แหล่งที่มา
comment
คุณหมายถึงการหมุนจากแนวนอนเป็นแนวตั้งใช่หรือไม่? (ถ้าใช่ให้เปลี่ยนความกว้างและความสูง) ตัวแปรมุมคืออะไร?   -  person Ming-Tang    schedule 14.04.2010
comment
ไม่แน่นอน เพียงพลิกในแนวตั้ง.. ดูภาพหน้าจอนี้: i42.tinypic.com/71jpqa.jpg   -  person smallmeans    schedule 14.04.2010


คำตอบ (1)


ขุดไปรอบ ๆ และพบวิธีแก้ปัญหาการทำงานนี้

context.scale(1,-1); //flip vertically 
context.translate(0,-height); //move beneath original position

ทำงานได้อย่างมหัศจรรย์!

person smallmeans    schedule 14.04.2010
comment
สิ่งนี้จะใช้ได้กับรูปภาพบิตแมปด้วยหรือไม่ ฉันมีปัญหาที่นั่น.. =/ - person Shouvik; 10.11.2010
comment
หากคุณได้รับอนุญาตให้ใช้ CSS3 คุณอาจใช้การแปลง CSS ที่คล้ายกันได้ - person Juho Vepsäläinen; 05.05.2011