HTML5 CANVAS draw image

后端 未结 2 421
我寻月下人不归
我寻月下人不归 2020-12-31 23:26

Here is my question

I kind of not understand what is the sx and sy is for in below function

context.drawImage(Image, sx, sy, sw, sh, dx, dy, dw, dh);

<
2条回答
  •  天命终不由人
    2020-12-31 23:37

    (sx, sy) is the top-left corner of the source rectangle (within the source image) which are going to draw to the destination. Take a look at the diagram below:

    enter image description here

    [Reference]

    sx=0,sy=0 is different from sx=300,sy=300 because they refer to different source rectangles.

提交回复
热议问题