在 Android 上的簡報中套用形狀效果
簡介
雖然 PowerPoint 中的效果可用於讓形狀凸顯,但它們不同於 填色 或輪廓。使用 PowerPoint 效果,您可以在形狀上建立逼真的反射、擴散形狀的發光等等。

PowerPoint 提供六種可套用於形狀的效果。您可以對形狀套用一個或多個效果。
某些效果組合比其他組合更好看。為此,PowerPoint 在 Preset 下提供選項。預設選項是兩個或多個已知外觀良好的效果組合。這樣,透過選取預設,您不必耗費時間測試或組合不同效果以找到合適的組合。
Aspose.Slides 在 EffectFormat 類別下提供屬性與方法,讓您能在 PowerPoint 簡報中套用相同的效果於形狀。
套用陰影效果
Aspose.Slides for Android via Java 支援形狀的外部和內部陰影。您可以自訂其顏色、方向、距離與模糊半徑,以符合簡報的設計。
套用外部陰影
使用外部陰影可讓卡片或面板在投影片背景中脫穎而出。陰影延伸至形狀邊緣之外,營造形狀浮於投影片之上的感覺。調整其顏色、方向、距離與模糊半徑,以符合範本的光線與樣式。
此 Java 程式碼示範如何將 外部陰影效果 套用到矩形:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IShape shape = slide.getShapes().addAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 100);
shape.getEffectFormat().enableOuterShadowEffect();
shape.getEffectFormat().getOuterShadowEffect().getShadowColor().setColor(Color.rgb(169, 169, 169));
shape.getEffectFormat().getOuterShadowEffect().setDistance(10);
shape.getEffectFormat().getOuterShadowEffect().setDirection(45);
presentation.save("shadow_effect.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}

套用內部陰影
在重現範本的視覺樣式時,使用內部陰影可讓卡片或面板呈現凹陷外觀。外部陰影延伸至形狀外部,使其看起來提升;而內部陰影則在邊緣內側投射陰影。
呼叫 enableInnerShadowEffect,然後設定由 getInnerShadowEffect 取得的陰影。較大的模糊半徑值會產生較柔和的邊緣。
此 Java 範例建立一個淡藍色卡片,搭配深灰色內部陰影,並將其儲存為 PPTX 檔案。陰影方向為 225 度,距離為 7 點,模糊半徑為 6 點:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 200, 100);
shape.getFillFormat().setFillType(FillType.Solid);
shape.getFillFormat().getSolidFillColor().setColor(Color.rgb(173, 216, 230));
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
shape.getEffectFormat().enableInnerShadowEffect();
IInnerShadow shadow = shape.getEffectFormat().getInnerShadowEffect();
shadow.getShadowColor().setColor(Color.rgb(105, 105, 105));
shadow.setDirection(225);
shadow.setDistance(7);
shadow.setBlurRadius(6);
presentation.save("inner_shadow_effect.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}

若要移除內部陰影,請對形狀的 effect format 呼叫 disableInnerShadowEffect。
套用反射效果
要在 Aspose.Slides for Android via Java 中套用反射效果,您可以為形狀新增鏡像般的反射,並調整距離、透明度與大小等參數。此效果可提升簡報的美感,讓形狀看起來更精緻、更具專業感。只需簡單程式碼即可快速在多個元素上套用,確保設計一致。
此 Java 程式碼示範如何將 反射效果 套用到形狀:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IShape shape = slide.getShapes().addAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 100);
shape.getEffectFormat().enableReflectionEffect();
shape.getEffectFormat().getReflectionEffect().setRectangleAlign(RectangleAlignment.Bottom);
shape.getEffectFormat().getReflectionEffect().setDirection(90);
shape.getEffectFormat().getReflectionEffect().setDistance(40);
shape.getEffectFormat().getReflectionEffect().setBlurRadius(2);
presentation.save("reflection_effect.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}

套用發光效果
要在 Aspose.Slides for Android via Java 中為形狀套用發光效果,您可以在形狀周圍加入柔和、發光的光暈,並調整顏色與大小等屬性。此效果有助於凸顯形狀,為簡報增添吸睛的視覺元素。只需少量程式碼即可實作,提升投影片的整體外觀。
此 Java 程式碼示範如何將 發光效果 套用到形狀:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IShape shape = slide.getShapes().addAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 100);
shape.getEffectFormat().enableGlowEffect();
shape.getEffectFormat().getGlowEffect().getColor().setColor(Color.MAGENTA);
shape.getEffectFormat().getGlowEffect().setRadius(15);
presentation.save("glow_effect.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}

套用柔和邊緣效果
要在 Aspose.Slides for Android via Java 中套用柔和邊緣效果,您可以在形狀的邊緣周圍建立平滑、模糊的過渡。此效果可為設計增添更細膩、精緻的外觀,適用於需要柔和外觀的版面。您可以輕鬆調整半徑等參數,以在簡報中的各式形狀上實現理想效果。
此 Java 程式碼示範如何將 柔和邊緣效果 套用到形狀:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IShape shape = slide.getShapes().addAutoShape(ShapeType.RoundCornerRectangle, 20, 20, 200, 150);
shape.getEffectFormat().enableSoftEdgeEffect();
shape.getEffectFormat().getSoftEdgeEffect().setRadius(8);
presentation.save("soft_edges_effect.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}

套用模糊效果
使用形狀模糊可在保持形狀可編輯的同時,柔化其填色與輪廓。對形狀的 effect format 呼叫 setBlurEffect。半徑以點 (1/72 英吋) 為單位:使用非負值,較大的值會產生更強的模糊。半徑為零則不改變外觀。
getGrow 設定控制效果的可見範圍。設定為 false 時,模糊會被裁切至原始繪製範圍(含輪廓);設定為 true 時,模糊可延伸超出該範圍。無論哪種設定,都不會改變形狀的位置或尺寸。
以下比較使用相同的填色、輪廓與形狀尺寸。上排使用 grow = false;下排使用 grow = true。

此 Java 範例建立一個橙色矩形,搭配深藍色輪廓,先套用 5 點模糊,然後再次呼叫 setBlurEffect 將模糊調整為 15 點。它會儲存兩個模糊狀態,接著呼叫 disableBlurEffect 並儲存無模糊的形狀。
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 80, 160, 100);
shape.getFillFormat().setFillType(FillType.Solid);
shape.getFillFormat().getSolidFillColor().setColor(Color.rgb(255, 165, 0));
shape.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.rgb(0, 0, 139));
shape.getLineFormat().setWidth(8);
shape.getEffectFormat().setBlurEffect(5, false);
presentation.save("shape_blur_5.pptx", SaveFormat.Pptx);
shape.getEffectFormat().setBlurEffect(15, true);
presentation.save("shape_blur_15.pptx", SaveFormat.Pptx);
shape.getEffectFormat().disableBlurEffect();
presentation.save("shape_blur_removed.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
形狀模糊同時影響填色與輪廓。柔和邊緣效果會淡化形狀的邊緣,而陰影模糊僅柔化陰影。影像變換效果作用於影像內容;此範例直接在形狀的 effect format 上套用模糊,而不需將形狀轉換為影像。
常見問題
我可以對同一個形狀套用多個效果嗎?
可以,您可以在單一形狀上結合不同的效果,例如陰影、反射與發光,以創造更具動態的外觀。
我可以對哪些形狀套用效果?
您可以對各種形狀套用效果,包括自動圖形、圖表、表格、圖片、SmartArt 物件、OLE 物件等等。
我可以對群組形狀套用效果嗎?
可以,您可以對群組形狀套用效果,該效果將套用於整個群組。