圖片與群組
圖片是一級投影片元素。處理 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() 會列出投影片的頂層群組。
你覺得這篇文檔如何?