Home > PCB_ImageTool > processImage
PCB_ImageTool.processImage() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
警告:此 API 现已弃用。
临时接口(插入图片 PCB 迁移打通流程用):等统一放置接口重构落地后删除替换,请尽快迁移,勿在新功能中继续依赖
选图处理门面(弹窗内重选图片:校验/压缩/读尺寸/预览 dataURL 全由服务端完成)
签名
typescript
function processImage(
file: File,
options?: { maxBytes?: number; acceptableBytes?: number },
): Promise<{
file: File;
dataURL: string;
width: number;
height: number;
actualFormat: string;
msg: string;
}>;1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
参数名
参数 | 类型 | 描述 |
|---|---|---|
file | File | 弹窗内重选 |
options | { maxBytes?: number; acceptableBytes?: number } | (可选) 可选参数 |
返回值
Promise<{ file: File; dataURL: string; width: number; height: number; actualFormat: string; msg: string; }>
处理结果:file 压缩后文件;dataURL 预览图 dataURL(decode 失败为空字符串);width/height 原始自然尺寸;actualFormat 原图实际格式(magic bytes 探测,识别失败为空串);msg 提示消息
备注
注意:msg 仅作为提示文本返回,**服务端已内部弹出 ToastMsg**(getImageInfoByFileWithProgressTip 内部 toast), 扩展侧**无需也不应**再对 msg 调用 showMessage,否则会双弹;仅当扩展需要自绘提示时才消费该字段。
示例
javascript
// 弹窗内重选图片:选择 → 处理 → 更新预览(提示已由服务端 toast,此处不重复弹)
const file = await eda.sys_FileSystem.openReadFileDialog(['.png', '.jpg']);
if (!file) {
return;
}
const res = await eda.pcb_ImageTool.processImage({ file });
if (res.dataURL) {
// 更新预览:res.dataURL(图)、res.width/res.height(原始尺寸)
console.log('图片已就绪:', res.file.name, res.width, res.height);
}1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10