From e779f2c7b8f61de12cb6a44aee2c4bc13c318921 Mon Sep 17 00:00:00 2001 From: ffx0s Date: Fri, 6 Sep 2019 15:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20IOS=20=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=90=8E=E8=B6=85=E5=87=BA=E8=A3=81=E5=89=AA?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=EF=BC=8C=E8=B0=83=E7=94=A8=E8=A3=81=E5=89=AA?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=90=8E=E5=9B=BE=E7=89=87=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=BB=91=E5=B1=8F=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/crop.js | 15 +++++++++++++-- src/canvas/validation.js | 9 +++++++-- src/crop/index.js | 5 ++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/dist/crop.js b/dist/crop.js index af35554..25a60f8 100644 --- a/dist/crop.js +++ b/dist/crop.js @@ -1926,6 +1926,7 @@ var validation = { validation: function validation(position, isDraw) { + var transition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; var that = this; position = position || that.position; var _that$options = that.options, @@ -1963,7 +1964,16 @@ } if (isDraw && result.isDraw) { - that.animate(result.x, result.y, result.scale); + if (transition) { + that.animate(result.x, result.y, result.scale); + } else { + that.setData({ + x: result.x, + y: result.y, + scale: result.scale + }); + that.draw(); + } } return result; @@ -2294,6 +2304,7 @@ key: "get", value: function get(options) { var crop = this; + crop.canvas.validation(null, true, false); var canvasRatio = crop.options.canvasRatio; var _crop$canvas$position = crop.canvas.position, scale = _crop$canvas$position.scale, @@ -2325,7 +2336,7 @@ if (antialiasing) { _canvas = antialisScale(_drawImage(clipWidth, clipHeight), clipScale); } else { - _canvas = _drawImage(options.width, Math.round(clipHeight * (options.width / clipWidth))); + _canvas = _drawImage(options.width, Math.round(clipHeight * clipScale)); } var format = { diff --git a/src/canvas/validation.js b/src/canvas/validation.js index 7b36961..3b0c221 100644 --- a/src/canvas/validation.js +++ b/src/canvas/validation.js @@ -1,7 +1,7 @@ import { calculate } from './helper' export default { - validation (position, isDraw) { + validation (position, isDraw, transition = true) { const that = this position = position || that.position const { maxScale, minScale } = that.options @@ -30,7 +30,12 @@ export default { } if (isDraw && result.isDraw) { - that.animate(result.x, result.y, result.scale) + if (transition) { + that.animate(result.x, result.y, result.scale) + } else { + that.setData({ x: result.x, y: result.y, scale: result.scale }) + that.draw() + } } return result diff --git a/src/crop/index.js b/src/crop/index.js index c2de62d..60fc544 100644 --- a/src/crop/index.js +++ b/src/crop/index.js @@ -143,6 +143,9 @@ class Crop { get (options) { const crop = this + + crop.canvas.validation(null, true, false) + const { canvasRatio } = crop.options const { scale, x, y } = crop.canvas.position const clipWidth = crop.border.width * canvasRatio / scale @@ -180,7 +183,7 @@ class Crop { if (antialiasing) { canvas = antialisScale(_drawImage(clipWidth, clipHeight), clipScale) } else { - canvas = _drawImage(options.width, Math.round(clipHeight * (options.width / clipWidth))) + canvas = _drawImage(options.width, Math.round(clipHeight * clipScale)) } const format = {