Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 CANVAS draw image

Tags:

html

image

draw

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);

what I really mean is if we change the values of sx and sy and set our dx and dy to a fix value, let say dx=0 and dy=0, is there really going to make any different to our image on the canvas when we set sx=300 and sy=300 as compared to sx=0 and sy=0? I mean the destination image is still in the location dx=dy=0 even we set sx and sy to different values, right? I know this is a stupid question but I just need to know the answer, thanks!

like image 376
mr.choose Avatar asked May 19 '11 15:05

mr.choose


1 Answers

(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.

like image 128
dogbane Avatar answered Sep 20 '22 09:09

dogbane