跳到主要内容

ReplaceCurrentImage

用指定的图像替换当前图像。

语法

expression.ReplaceCurrentImage(sImageUrl, Width, Height);

expression - 表示 ApiPresentation 类的变量。

参数

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

返回值

此方法不返回任何数据。

示例

此示例演示如何用指定的图像替换当前图像。

// How to replace an image with another one.

// Replace the current ApiImage with another image on the slide.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const url1 = 'https://static.onlyoffice.com/assets/docs/samples/img/presentation_sky.png';
const url2 = 'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png';

const drawing = Api.CreateImage(url1, 300 * 36000, 150 * 36000);
slide.AddObject(drawing);
drawing.Select();
presentation.ReplaceCurrentImage(url2, 60 * 36000, 60 * 36000);