HTML5 Canvas putImageData, translate it, change Image

前端 未结 2 858
灰色年华
灰色年华 2021-01-14 09:57

I want to draw an image using a HTML5 canvas, translate the image and then change the image but keep the transformations I\'ve made. Is this possible?

Here\'s some p

2条回答
  •  一个人的身影
    2021-01-14 10:07

    The problem here is that putImageData is not affected by the transformation matrix.

    This is by the Spec's orders:

    The current path, transformation matrix, shadow attributes, global alpha, the clipping region, and global composition operator must not affect the getImageData() and putImageData() methods.

    What you can do is putImageData to an in-memory canvas, and then

    inMemCtx.putImageData(imgdata, 0, 0);
    context.drawImage(inMemoryCanvas, x, y)
    

    onto your regular canvas, and the translation will be applied to the drawImage call.

提交回复
热议问题