diff --git a/src/core/helpers/protocol/canvas.js b/src/core/helpers/protocol/canvas.js index fb9b55611b3a6cfee1160783fb0e911d1d8e3a2c..c07196005f605cf9fc70d3ba460f7211e8e75830 100644 --- a/src/core/helpers/protocol/canvas.js +++ b/src/core/helpers/protocol/canvas.js @@ -1,3 +1,11 @@ +function getInt (method) { + return function (value, params) { + if (value) { + params[method] = Math.round(value) + } + } +} + export const canvasGetImageData = { canvasId: { type: String, @@ -5,19 +13,23 @@ export const canvasGetImageData = { }, x: { type: Number, - required: true + required: true, + validator: getInt('x') }, y: { type: Number, - required: true + required: true, + validator: getInt('y') }, width: { type: Number, - required: true + required: true, + validator: getInt('width') }, height: { type: Number, - required: true + required: true, + validator: getInt('height') } } @@ -32,18 +44,22 @@ export const canvasPutImageData = { }, x: { type: Number, - required: true + required: true, + validator: getInt('x') }, y: { type: Number, - required: true + required: true, + validator: getInt('y') }, width: { type: Number, - required: true + required: true, + validator: getInt('width') }, height: { - type: Number + type: Number, + validator: getInt('height') } } @@ -55,23 +71,29 @@ const fileType = { export const canvasToTempFilePath = { x: { type: Number, - default: 0 + default: 0, + validator: getInt('x') }, y: { type: Number, - default: 0 + default: 0, + validator: getInt('y') }, width: { - type: Number + type: Number, + validator: getInt('width') }, height: { - type: Number + type: Number, + validator: getInt('height') }, destWidth: { - type: Number + type: Number, + validator: getInt('destWidth') }, destHeight: { - type: Number + type: Number, + validator: getInt('destHeight') }, canvasId: { type: String, diff --git a/src/core/service/api/context/canvas.js b/src/core/service/api/context/canvas.js index 1c8872e15fb68161c6730dcb8c73d5528ca9271b..3443a5506a418cd6d494493c79b89b58e697bd1b 100644 --- a/src/core/service/api/context/canvas.js +++ b/src/core/service/api/context/canvas.js @@ -682,7 +682,14 @@ export function canvasToTempFilePath ({ }) return } - imgData = new ImageData(new Uint8ClampedArray(imgData), data.width, data.height) + try { + imgData = new ImageData(new Uint8ClampedArray(imgData), data.width, data.height) + } catch (error) { + invoke(callbackId, { + errMsg: 'canvasToTempFilePath:fail' + }) + return + } var canvas = getTempCanvas() canvas.width = data.width canvas.height = data.height diff --git a/src/core/view/components/canvas/index.vue b/src/core/view/components/canvas/index.vue index f060723a690ebeff09b8c51f5865599a23309d17..50212e8adc5b312d0df79f5774c46b0618db6be7 100644 --- a/src/core/view/components/canvas/index.vue +++ b/src/core/view/components/canvas/index.vue @@ -383,7 +383,7 @@ export default { }) { try { if (!height) { - height = data.length / 4 / width + height = Math.round(data.length / 4 / width) } this.$refs.canvas.getContext('2d').putImageData(new ImageData(new Uint8ClampedArray(data), width, height), x, y) } catch (error) {