PowerPoint.ShapeGetImageOptions interface
表示获取形状图像时的可用选项。 图像被缩放以适应所需的尺寸。 如果未指定宽度和高度,则使用形状的实际大小。 如果仅指定了宽度或高度中的一个,则将计算另一个以保持纵横比。 如果生成的尺寸太大,将自动固定为最大支持尺寸。
注解
使用方
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shape-as-image.yaml
// Gets an image of the first selected shape with all options specified:
// a fixed width, height, and explicit PNG format.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
await context.sync();
if (shapeCount.value === 0) {
console.warn("No shapes are selected. Please select a shape and try again.");
return;
}
const shape: PowerPoint.Shape = shapes.getItemAt(0);
const options: PowerPoint.ShapeGetImageOptions = {
format: PowerPoint.ShapeGetImageFormatType.png,
width: 300,
height: 150,
// Both width and height are specified, so the image is scaled to fit within
// 300x150 pixels. The image may not fill both dimensions if the aspect ratios differ.
};
const imageResult: OfficeExtension.ClientResult<string> = shape.getImageAsBase64(options);
await context.sync();
displayImage(imageResult.value, "PNG, 300x150px");
});
属性
| format | 生成图像的所需格式。 |
| height | 生成图像的所需高度(以像素为单位)。 如果此值太大,将自动固定为支持的最大大小。 使用非正整数设置时引 |
| width | 生成图像的所需宽度(以像素为单位)。 如果此值太大,将自动固定为支持的最大大小。 使用非正整数设置时引 |
属性详细信息
format
生成图像的所需格式。
format?: PowerPoint.ShapeGetImageFormatType | "Png";
属性值
注解
height
生成图像的所需高度(以像素为单位)。 如果此值太大,将自动固定为支持的最大大小。 使用非正整数设置时引 InvalidArgument 发异常。
height?: number;
属性值
number
注解
width
生成图像的所需宽度(以像素为单位)。 如果此值太大,将自动固定为支持的最大大小。 使用非正整数设置时引 InvalidArgument 发异常。
width?: number;
属性值
number