kfb-view 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/workspace.xml +34 -30
- package/example/index.js +20 -17
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/tailoring/index.js +32 -4
- package/src/view.js +3 -0
package/package.json
CHANGED
|
@@ -29,7 +29,12 @@ export class Tailoring extends ViewerCommon {
|
|
|
29
29
|
this.movePointIndex = -1;
|
|
30
30
|
this.color = '#FFF';
|
|
31
31
|
this.contents = [];
|
|
32
|
-
this.
|
|
32
|
+
this.options = {
|
|
33
|
+
suffix: 'jpeg',
|
|
34
|
+
quality: 0.92,
|
|
35
|
+
resolution: 1200,
|
|
36
|
+
...this.options,
|
|
37
|
+
};
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
init({
|
|
@@ -40,11 +45,9 @@ export class Tailoring extends ViewerCommon {
|
|
|
40
45
|
color,
|
|
41
46
|
now = false,
|
|
42
47
|
contents = [],
|
|
43
|
-
suffix = 'jpeg',
|
|
44
48
|
}) {
|
|
45
49
|
this.isInTailoring = true;
|
|
46
50
|
this.movePointIndex = -1;
|
|
47
|
-
this.imageType = suffix;
|
|
48
51
|
const pointList = getRectPoint({x: left, y: top},
|
|
49
52
|
{x: left + width, y: top + height});
|
|
50
53
|
this.tailoringPoints = [
|
|
@@ -296,10 +299,20 @@ export class Tailoring extends ViewerCommon {
|
|
|
296
299
|
const imageData =
|
|
297
300
|
ctx.getImageData(
|
|
298
301
|
startPoint.x * radioX, startPoint.y * radioY, disWidth, disHeight);
|
|
302
|
+
for (let i = 0; i < imageData.data.length; i += 4) {
|
|
303
|
+
if (imageData.data[i + 3] === 0) {
|
|
304
|
+
imageData.data[i] = 255;
|
|
305
|
+
imageData.data[i + 1] = 255;
|
|
306
|
+
imageData.data[i + 2] = 255;
|
|
307
|
+
imageData.data[i + 3] = 255;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
299
310
|
const copyCanvas = document.createElement('canvas');
|
|
300
311
|
copyCanvas.width = disWidth;
|
|
301
312
|
copyCanvas.height = disHeight;
|
|
302
313
|
const copyCtx = copyCanvas.getContext('2d');
|
|
314
|
+
copyCtx.fillstyle = '#fff';
|
|
315
|
+
copyCtx.fillRect(0, 0, copyCanvas.width, copyCanvas.height);
|
|
303
316
|
copyCtx.putImageData(imageData, 0, 0, 0, 0, disWidth, disHeight);
|
|
304
317
|
const shapeCanvas = this.kv.shape?.canvas;
|
|
305
318
|
if (shapeCanvas) {
|
|
@@ -307,7 +320,22 @@ export class Tailoring extends ViewerCommon {
|
|
|
307
320
|
startPoint.y * radioY, disWidth, disHeight, 0, 0, disWidth,
|
|
308
321
|
disHeight);
|
|
309
322
|
}
|
|
310
|
-
|
|
323
|
+
if (copyCanvas.width > this.options.resolution) {
|
|
324
|
+
const maxCanvas = document.createElement('canvas');
|
|
325
|
+
maxCanvas.width = this.options.resolution;
|
|
326
|
+
maxCanvas.height = this.options.resolution / copyCanvas.width *
|
|
327
|
+
copyCanvas.height;
|
|
328
|
+
const maxCtx = maxCanvas.getContext('2d');
|
|
329
|
+
maxCtx.fillstyle = '#fff';
|
|
330
|
+
maxCtx.fillRect(0, 0, maxCanvas.width, maxCanvas.height);
|
|
331
|
+
maxCtx.drawImage(copyCanvas, 0, 0, copyCanvas.width, copyCanvas.height,
|
|
332
|
+
0, 0, maxCanvas.width, maxCanvas.height);
|
|
333
|
+
return maxCanvas.toDataURL(`image/${this.options.suffix || 'jpeg'}`,
|
|
334
|
+
this.options.quality);
|
|
335
|
+
} else {
|
|
336
|
+
return copyCanvas.toDataURL(`image/${this.options.suffix || 'jpeg'}`,
|
|
337
|
+
this.options.quality);
|
|
338
|
+
}
|
|
311
339
|
} catch (e) {
|
|
312
340
|
console.error(e);
|
|
313
341
|
}
|
package/src/view.js
CHANGED
|
@@ -51,6 +51,9 @@ export default class KfbView extends EventEmitter {
|
|
|
51
51
|
* @param {boolean=} config.rotation.disabled 是否禁用旋转
|
|
52
52
|
* @param {Object} config.tailoring 裁剪图像参数
|
|
53
53
|
* @param {boolean=} config.tailoring.disabled 是否禁用裁剪
|
|
54
|
+
* @param {string=} config.tailoring.suffix 截图后缀
|
|
55
|
+
* @param {number=} config.tailoring.quality 截图的质量
|
|
56
|
+
* @param {number=} config.tailoring.resolution 分辨率
|
|
54
57
|
* @param {Object} config.shape 显示标注图形
|
|
55
58
|
* @param {boolean=} config.shape.disabled 是否禁用标注
|
|
56
59
|
* @param {Object} config.board 标注参数
|