Home > IPCB_PrimitiveObject > setState_BinaryData
IPCB_PrimitiveObject.setState_BinaryData() method
Set the property state: binary data
Signature
typescript
function setState_BinaryData(binaryData: string): IPCB_PrimitiveObject;1
Parameters
Parameter | Type | Description |
|---|---|---|
binaryData | string | Binary data |
Returns
Binary embedded object primitive object
Remarks
The binaryData re-retrieved from the canvas may be a hashId, because our backend stores binary embedded object data in object storage,
The object storage uses hashId as the index. Fully retrieving the data will cause additional requests and consume performance
Example
javascript
// 1. 生成本次运行专用的坐标,放置一个 4x4 图片的内嵌对象
const x = 2000 + Math.floor(Math.random() * 100000);
const y = 2000 + Math.floor(Math.random() * 100000);
// 4x4 纯色 PNG 的 data URI(binaryData 必须是 data URI 格式,裸 base64 会创建失败)
const oldImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAEElEQVR4nGP4z8AARwzEcQCukw/x0F8jngAAAABJRU5ErkJggg==';
// 8x8 纯色 PNG 的 data URI,作为替换用的新图
const newImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAEklEQVR4nGOQi7rzHx9mGBkKAFPclMHPGdtKAAAAAElFTkSuQmCC';
const obj = await eda.pcb_PrimitiveObject.create(3, x, y, oldImage, 400, 300, 0, false, 'demo.png', false);
const before = obj.getState_BinaryData().length;
// 2. 异步模式替换为新图片数据
const asyncObj = obj.toAsync();
asyncObj.setState_BinaryData(newImage);
await asyncObj.done();
// 3. 从画布重新读取,确认数据已更新(保留现场供观察)
const refetched = await eda.pcb_PrimitiveObject.get(obj.getState_PrimitiveId());
console.log('binaryData 长度:', before, '→', refetched.getState_BinaryData().length);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19