From f102739d49132fe49e15f96f5b171ec89628ff1b Mon Sep 17 00:00:00 2001 From: raphael Date: Tue, 2 Jun 2020 18:11:52 +0200 Subject: [PATCH] add image faster (without canvas save+reload) if we have no rotation --- src/js/whiteboard.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/js/whiteboard.js b/src/js/whiteboard.js index 9b66408..63c8834 100644 --- a/src/js/whiteboard.js +++ b/src/js/whiteboard.js @@ -987,12 +987,15 @@ const whiteboard = { var img = document.createElement("img"); img.onload = function () { rotationAngle = rotationAngle ? rotationAngle : 0; - _this.ctx.save(); - _this.ctx.translate(left + width / 2, top + height / 2); - _this.ctx.rotate(rotationAngle); - _this.ctx.drawImage(img, -(width / 2), -(height / 2), width, height); - _this.ctx.restore(); - //_this.ctx.drawImage(img, left, top, width, height); + if (rotationAngle === 0) { + _this.ctx.drawImage(img, left, top, width, height); + } else { + _this.ctx.save(); + _this.ctx.translate(left + width / 2, top + height / 2); + _this.ctx.rotate(rotationAngle); + _this.ctx.drawImage(img, -(width / 2), -(height / 2), width, height); + _this.ctx.restore(); + } if (doneCallback) { doneCallback(); }