Copy and crop images in Javascript

前端 未结 4 1271
死守一世寂寞
死守一世寂寞 2020-12-15 00:57

I\'m trying to create a small 2D game in Javascript/Canvas which consists of several animated sprites. I\'d like to cut down on the number of HTTP requests, so I combined ea

4条回答
  •  -上瘾入骨i
    2020-12-15 01:20

    The HTML5 Canvas API provides a method called drawImage which allows you to crop the input image.

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

    alt text

    For more information see the spec (that image is taken directly from the spec):

    http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#images

提交回复
热议问题