简体   繁体   中英

How to rotate an image that will be drawn on to canvas?

so having a canvas and canvasContext I want to draw an image onto that canvas multiple times

So I have code like:

  var img = new Image();
  img.src = 'http://superior0.narod.ru/5050.png';
function drawLine(g, n, x1, y1, x2, y2){

   g.drawImage(img,x1,y1,10,10); 
}

here i do not rotate an image. I need it to be rotated in form of how line would be rotated if drawn from point x1, y1 to x2, y2.

How to do such thing in HTML5 and Javascript? (Having to use only one canvas)

You can see problem in acrion here

Use the rotate method of the context, taking care to invoke the rotate and translate in the correct order (which can be tricky if you're not used to matrix transformations). Quick example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM