画像とグループ
画像はスライドの第一級要素です。URL や Blob には非同期ヘルパーを使い、すべての画像プロパティが分かっている場合はビルダーを使用します。
画像を挿入する
TypeScript
const slide = univerAPI.getActivePresentation()?.getActiveSlide()if (!slide) { throw new Error('No active slide')}const image = await slide.insertImageAsync( 'https://example.com/assets/diagram.png', { imageSourceType: univerAPI.Enum.ImageSourceType.URL, left: 80, top: 120, width: 320, height: 180, })getImages() は現在のスライド上の画像を返します。既存画像の更新には setSource()、setCrop()、setClipShape()、toBuilder() を使い、削除には removeImage() を使用します。
要素をグループ化する
TypeScript
const shape = slide.getShapes()[0]if (shape) { const group = slide.group([shape, image]) const children = group.getChildren() // 子要素をスライドに戻します。 slide.ungroup(group)}グループは子要素の順序を保ち、他のページ要素と同じ変形、表示、名前、説明のメソッドを提供します。getGroups() は最上位グループを列挙します。
このガイドはいかがですか?