Home > PCB_PrimitiveImage > create
PCB_PrimitiveImage.create() method
创建图像
签名
typescript
function create(
x: number,
y: number,
complexPolygon:
| TPCB_PolygonSourceArray
| Array<TPCB_PolygonSourceArray>
| IPCB_Polygon
| IPCB_ComplexPolygon,
layer: TPCB_LayersOfImage,
width?: number,
height?: number,
rotation?: number,
horizonMirror?: boolean,
primitiveLock?: boolean,
): Promise<IPCB_PrimitiveImage | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
参数名
参数 | 类型 | 描述 |
|---|---|---|
x | number | BBox 左上点坐标 X |
y | number | BBox 左上点坐标 Y |
complexPolygon | TPCB_PolygonSourceArray | Array<TPCB_PolygonSourceArray> | IPCB_Polygon | IPCB_ComplexPolygon | 图像源数据(复杂多边形),可以使用 PCB_MathPolygon.convertImageToComplexPolygon() 方法将图像文件转换为复杂多边形数据 |
layer | 层 | |
width | number | (可选) 宽 |
height | number | (可选) 高 |
rotation | number | (可选) 旋转角度 |
horizonMirror | boolean | (可选) 是否水平镜像 |
primitiveLock | boolean | (可选) 是否锁定 |
返回值
Promise<IPCB_PrimitiveImage | undefined>
图像图元对象
备注
如需创建彩色丝印图像,请使用 二进制内嵌对象图元类
示例
javascript
// 1. 生成随机基准坐标,避免与画布上已有的图像重合
const x = 2000 + Math.floor(Math.random() * 100000);
const y = 2000 + Math.floor(Math.random() * 100000);
// 2. 构造折线多边形轮廓(局部坐标 200×150 的五边形),图像轮廓必须是 ComplexPolygon 对象
const complexPolygon = eda.pcb_MathPolygon.createComplexPolygon([
0,
0,
'L',
200,
0,
200,
150,
100,
220,
0,
150
]);
// 3. 在顶层铜层(1)创建图像,宽 400、高 300,不旋转、不镜像、不锁定
const image = await eda.pcb_PrimitiveImage.create(x, y, complexPolygon, 1, 400, 300, 0, false, false);
// 4. 创建类保留现场,不删除图元
console.log('primitiveId:', image.getState_PrimitiveId());
console.log('layer:', image.getState_Layer());
console.log('width:', image.getState_Width());
console.log('height:', image.getState_Height());
console.log('primitiveType:', image.getState_PrimitiveType());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28