Skip to content

Commit

Permalink
修复 IOS 移动图片后超出裁剪范围,调用裁剪方法后图片出现黑屏问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
ffx0s committed Sep 6, 2019
1 parent 1840869 commit e779f2c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
15 changes: 13 additions & 2 deletions dist/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
9 changes: 7 additions & 2 deletions src/canvas/validation.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/crop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit e779f2c

Please sign in to comment.