kfb-view 3.0.1 → 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 +47 -39
- package/example/index.js +20 -17
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/tailoring/index.js +41 -2
- package/src/view.js +3 -0
package/package.json
CHANGED
|
@@ -29,9 +29,23 @@ export class Tailoring extends ViewerCommon {
|
|
|
29
29
|
this.movePointIndex = -1;
|
|
30
30
|
this.color = '#FFF';
|
|
31
31
|
this.contents = [];
|
|
32
|
+
this.options = {
|
|
33
|
+
suffix: 'jpeg',
|
|
34
|
+
quality: 0.92,
|
|
35
|
+
resolution: 1200,
|
|
36
|
+
...this.options,
|
|
37
|
+
};
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
init({
|
|
40
|
+
init({
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
43
|
+
left,
|
|
44
|
+
top,
|
|
45
|
+
color,
|
|
46
|
+
now = false,
|
|
47
|
+
contents = [],
|
|
48
|
+
}) {
|
|
35
49
|
this.isInTailoring = true;
|
|
36
50
|
this.movePointIndex = -1;
|
|
37
51
|
const pointList = getRectPoint({x: left, y: top},
|
|
@@ -285,10 +299,20 @@ export class Tailoring extends ViewerCommon {
|
|
|
285
299
|
const imageData =
|
|
286
300
|
ctx.getImageData(
|
|
287
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
|
+
}
|
|
288
310
|
const copyCanvas = document.createElement('canvas');
|
|
289
311
|
copyCanvas.width = disWidth;
|
|
290
312
|
copyCanvas.height = disHeight;
|
|
291
313
|
const copyCtx = copyCanvas.getContext('2d');
|
|
314
|
+
copyCtx.fillstyle = '#fff';
|
|
315
|
+
copyCtx.fillRect(0, 0, copyCanvas.width, copyCanvas.height);
|
|
292
316
|
copyCtx.putImageData(imageData, 0, 0, 0, 0, disWidth, disHeight);
|
|
293
317
|
const shapeCanvas = this.kv.shape?.canvas;
|
|
294
318
|
if (shapeCanvas) {
|
|
@@ -296,7 +320,22 @@ export class Tailoring extends ViewerCommon {
|
|
|
296
320
|
startPoint.y * radioY, disWidth, disHeight, 0, 0, disWidth,
|
|
297
321
|
disHeight);
|
|
298
322
|
}
|
|
299
|
-
|
|
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
|
+
}
|
|
300
339
|
} catch (e) {
|
|
301
340
|
console.error(e);
|
|
302
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 标注参数
|