必须套索之后才能调用该接口,否则会调用失败。
复制
static resizeLassoRect(rect: Rect): Promise<APIResponse<boolean>>;
| 参数 | 类型 | 说明 |
|---|---|---|
rect | Rect | 套索框矩形(像素坐标) |
APIResponse<boolean>:result === true表示调整成功
示例
复制
import { PluginCommAPI, type Rect } from 'sn-plugin-lib';
/**
* 按等比例缩放调整套索框矩形的示例。
*/
export async function exampleResizeLassoRect() {
const current = await PluginCommAPI.getLassoRect();
if (!current.success) {
throw new Error(current.error?.message ?? 'getLassoRect 调用失败');
}
const rect = current.result as Rect;
const w = rect.right - rect.left;
const h = rect.bottom - rect.top;
const cx = rect.left + w / 2;
const cy = rect.top + h / 2;
const scale = 1.2;
const nextRect: Rect = {
left: cx - (w * scale) / 2,
top: cy - (h * scale) / 2,
right: cx + (w * scale) / 2,
bottom: cy + (h * scale) / 2,
};
const res = await PluginCommAPI.resizeLassoRect(nextRect);
if (!res.success) {
throw new Error(res.error?.message ?? 'resizeLassoRect 调用失败');
}
return res.result;
}