Home > PCB_MathPolygon > convertImageToComplexPolygon
PCB_MathPolygon.convertImageToComplexPolygon() method
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Convert Image to Complex polygon object
Signature
function convertImageToComplexPolygon(
imageBlob: Blob,
imageWidth: number,
imageHeight: number,
tolerance?: number,
simplification?: number,
smoothing?: number,
despeckling?: number,
whiteAsBackgroundColor?: boolean,
inversion?: boolean,
): Promise<IPCB_ComplexPolygon | undefined>;2
3
4
5
6
7
8
9
10
11
Parameters
Parameter | Type | Description |
|---|---|---|
imageBlob | Blob | Image Blob file. You can use the method to read a file from the file system |
imageWidth | number | Image width |
imageHeight | number | Image height |
tolerance | number | (Optional) Tolerance, value range |
simplification | number | (Optional) Simplification, value range |
smoothing | number | (Optional) Smoothing, value range |
despeckling | number | (Optional) Despeckling, value range |
whiteAsBackgroundColor | boolean | (Optional) Whether to use white as the background color |
inversion | boolean | (Optional) Whether it is inverted |
Returns
Promise<IPCB_ComplexPolygon | undefined>
Complex polygon object
Example
// 1. 用 canvas 画一张测试图:白色背景,中间 10×10 像素的黑色方块
const canvas = document.createElement('canvas');
canvas.width = 20;
canvas.height = 20;
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, 20, 20);
ctx.fillStyle = '#000000';
ctx.fillRect(5, 5, 10, 10);
// 2. 导出为 PNG Blob
const imageBlob = await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
// 3. 描摹为复杂多边形(全部可选参数走默认值)
const complexPolygon = await eda.pcb_MathPolygon.convertImageToComplexPolygon(imageBlob, 20, 20);
// 4. 读取描摹结果:分块数量与第一块的源数据(描摹出的轮廓点,坐标由算法生成)
const sources = complexPolygon.getSourceStrictComplex();
console.log('polygonCount:', sources.length);
console.log('firstSource:', JSON.stringify(sources[0]).slice(0, 120));2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20