(I first posted this function in the Rotate Image on Canvas tutorial.
function drawImg(img, pX, pY, oX, oY, w, h, rot) { context2D.save(); context2D.translate(pX+oX, pY+oY); context2D.rotate(rot * Math.PI / 180); context2D.drawImage(img, 0, 0, w, h, -(oX), -(oY), w, h); context2D.restore(); }
Note:
img: the image object
pX: the x position of the image
pY: the y position of the image
oX: how far across the image that the origin is
oY: how far down the image that the origin is
w: width of the image
h: height of the image
rot: angle of rotation
No comments:
Post a Comment