How to horizontally flip an image

前端 未结 3 842
误落风尘
误落风尘 2021-01-19 05:59

How can i draw only two images with reversing I don\'t know how to reverse. Pls help.

    var canvas = document.createElement(\'canvas\');
          


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 06:25

    To mirror image you can use setTransform with negative scale.

    context.setTransform(-1, 0, 0, 1, 0, 0);    //Now all images will be horizontally mirrored
    context.drawImage(, srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth);
    

    Don't forget to restore transform when you finished.

    context.setTransform(1, 0, 0, 1, 0, 0);
    

提交回复
热议问题