跳到主要内容

CreateImage

使用指定的参数创建图像。

语法

expression.CreateImage(imageSrc, width, height);

expression - 表示 Api 类的变量。

参数

名称必需/可选数据类型默认值描述
imageSrc必需string要插入的图像来源(目前仅支持网络 URL 或 Base64 编码的图像)。
width必需EMU以英制度量单位表示的图像宽度。
height必需EMU以英制度量单位表示的图像高度。

返回值

ApiImage

示例

将 URL 图像插入到文档的段落中。

// How do I add an image with a specific width and height to a document?

// Place a remotely hosted picture at a fixed size inside a paragraph in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let image = Api.CreateImage(
'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png',
60 * 36000, 60 * 36000
);
paragraph.AddDrawing(image);