Home > PCB_ImageTool > processImage
PCB_ImageTool.processImage() 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.
Warning: This API is now obsolete.
临时接口(插入图片 PCB 迁移打通流程用):等统一放置接口重构落地后删除替换,请尽快迁移,勿在新功能中继续依赖
选图处理门面(弹窗内重选图片:校验/压缩/读尺寸/预览 dataURL 全由服务端完成)
Signature
function processImage(
file: File,
options?: { maxBytes?: number; acceptableBytes?: number },
): Promise<{
file: File;
dataURL: string;
width: number;
height: number;
actualFormat: string;
msg: string;
}>;2
3
4
5
6
7
8
9
10
11
Parameters
Parameter | Type | Description |
|---|---|---|
file | File | 弹窗内重选 |
options | { maxBytes?: number; acceptableBytes?: number } | (Optional) .acceptableBytes - 可接受大小(超过则压缩),默认 2M |
Returns
Promise<{ file: File; dataURL: string; width: number; height: number; actualFormat: string; msg: string; }>
处理结果:file 压缩后文件;dataURL 预览图 dataURL(decode 失败为空字符串);width/height 原始自然尺寸;actualFormat 原图实际格式(magic bytes 探测,识别失败为空串);msg 提示消息
Remarks
注意:msg 仅作为提示文本返回,**服务端已内部弹出 ToastMsg**(getImageInfoByFileWithProgressTip 内部 toast), 扩展侧**无需也不应**再对 msg 调用 showMessage,否则会双弹;仅当扩展需要自绘提示时才消费该字段。 ADD since EDA v5
Example
// 弹窗内重选图片:选择 → 处理 → 更新预览(提示已由服务端 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);
}2
3
4
5
6
7
8
9
10