Aplicar efeitos 3D no PowerPoint usando Java

Os efeitos 3D no PowerPoint são usados para tornar as apresentações mais atraentes e chamar a atenção dos usuários. Portanto, você pode se deparar com a necessidade de adicionar objetos 3D às apresentações programaticamente. Neste artigo, você aprenderá como criar efeitos 3D no PowerPoint PPT ou PPTX em Java. Mostraremos como criar texto e formas 3D e aplicar efeitos 3D às imagens.

API Java para aplicar efeitos 3D no PowerPoint PPT

Aspose.Slides for Java é uma API poderosa que encapsula uma ampla variedade de recursos de manipulação de apresentação. Usando a API, você pode criar apresentações interativas e manipular arquivos PPT/PPTX existentes sem problemas. Para criar efeitos 3D nas apresentações do PowerPoint, utilizaremos esta API.

Você pode baixar o JAR da API ou instalá-lo usando as seguintes configurações do Maven.

Repositório:

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

Dependência:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>22.1</version>
    <classifier>jdk16</classifier>
</dependency>

Criar um texto 3D no PowerPoint em Java

A seguir estão as etapas para criar um fragmento de texto 3D no PowerPoint PPT usando Java.

O exemplo de código a seguir mostra como criar texto 3D no PowerPoint PPT em Java.

// Criar apresentação
Presentation pres = new Presentation();
try {
    // Adicionar forma de retângulo
    IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);

    // Definir texto
    shape.getFillFormat().setFillType(FillType.NoFill);
    shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
    shape.getTextFrame().setText("3D Text");

    // Adicione parte de texto e defina suas propriedades
    Portion portion = (Portion)shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
    portion.getPortionFormat().getFillFormat().setFillType(FillType.Pattern);
    portion.getPortionFormat().getFillFormat().getPatternFormat().getForeColor().setColor(new Color(255, 140, 0));
    portion.getPortionFormat().getFillFormat().getPatternFormat().getBackColor().setColor(Color.WHITE);
    portion.getPortionFormat().getFillFormat().getPatternFormat().setPatternStyle(PatternStyle.LargeGrid);

    // Definir o tamanho da fonte do texto da forma
    shape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().setFontHeight(128);

    // Obter quadro de texto
    ITextFrame textFrame = shape.getTextFrame();

    // Configurar o efeito de transformação WordArt "Arch Up"
    textFrame.getTextFrameFormat().setTransform(TextShapeType.ArchUp);

    // Aplicar efeitos 3D
    textFrame.getTextFrameFormat().getThreeDFormat().setExtrusionHeight(3.5f);
    textFrame.getTextFrameFormat().getThreeDFormat().setDepth(3);
    textFrame.getTextFrameFormat().getThreeDFormat().setMaterial(MaterialPresetType.Plastic);
    textFrame.getTextFrameFormat().getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
    textFrame.getTextFrameFormat().getThreeDFormat().getLightRig().setLightType(LightRigPresetType.Balanced);
    textFrame.getTextFrameFormat().getThreeDFormat().getLightRig().setRotation(0, 0, 40);		 
    textFrame.getTextFrameFormat().getThreeDFormat().getCamera().setCameraType(CameraPresetType.PerspectiveContrastingRightFacing);

    // Salvar apresentação
    pres.save("3D-Text.pptx", SaveFormat.Pptx);
} finally {
    if (pres != null) pres.dispose();
}

A captura de tela a seguir mostra a saída do exemplo de código acima.

Criar um texto 3D no PowerPoint em Java

Criar uma forma 3D no PowerPoint em Java

Semelhante ao texto, você pode aplicar efeitos 3D às formas nas apresentações do PowerPoint. A seguir estão as etapas para criar uma forma 3D no PowerPoint PPT usando Java.

O exemplo de código a seguir mostra como aplicar efeitos 3D a formas no PowerPoint usando Java.

// Criar apresentação
Presentation pres = new Presentation();
try {
    // Adicionar forma de retângulo
    IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);

    // Definir texto para forma
    shape.getTextFrame().setText("3D");
    shape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().setFontHeight(64);

    // Aplicar efeitos 3D
    shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront);
    shape.getThreeDFormat().getCamera().setRotation(20, 30, 40);
    shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.Flat);
    shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
    shape.getThreeDFormat().setMaterial(MaterialPresetType.Flat);
    shape.getThreeDFormat().setExtrusionHeight(100);
    shape.getThreeDFormat().getExtrusionColor().setColor(Color.BLUE);

    // Salvar apresentação
    pres.save("3D-Shape.pptx", SaveFormat.Pptx);
} finally {
    if (pres != null) pres.dispose();
}

A seguir está a forma 3D que obtemos depois de executar este código.

Criar uma forma 3D no PowerPoint em Java

Criar gradiente para formas 3D

Você também pode aplicar efeitos de gradiente às formas seguindo as etapas abaixo.

O exemplo de código a seguir mostra como aplicar efeitos de gradiente a formas em um PowerPoint PPT.

// Criar apresentação
Presentation pres = new Presentation();
try {
    // Adicionar forma de retângulo
    IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);

    // Definir texto para forma
    shape.getTextFrame().setText("3D");
    shape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().setFontHeight(64);

    shape.getFillFormat().setFillType(FillType.Gradient);
    shape.getFillFormat().getGradientFormat().getGradientStops().add(0, Color.BLUE);
    shape.getFillFormat().getGradientFormat().getGradientStops().add(100, Color.MAGENTA);

    // Aplicar efeitos 3D
    shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront);
    shape.getThreeDFormat().getCamera().setRotation(10, 20, 30);
    shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.Flat);
    shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
    shape.getThreeDFormat().setExtrusionHeight(150);
    shape.getThreeDFormat().getExtrusionColor().setColor(new Color(255, 140, 0));

    // Salvar apresentação
    pres.save("3D-Shape-Gradient.pptx", SaveFormat.Pptx);
} finally {
    if (pres != null) pres.dispose();
}

A seguir está a forma 3D após a aplicação do efeito gradiente.

Criar gradiente para formas 3D em PPT em Java

Aplicar efeitos 3D a uma imagem no PowerPoint em Java

Aspose.Slides for Java também permite aplicar efeitos 3D a uma imagem. A seguir estão as etapas para executar esta operação em Java.

A seguir estão as etapas para aplicar efeitos 3D a uma imagem em PPT usando Java.

// Criar apresentação
Presentation pres = new Presentation();
try {
    // Adicionar forma de retângulo
    IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);

    // Definir imagem para forma
    shape.getFillFormat().setFillType(FillType.Picture);
    IPPImage picture = null;
    try {
        picture = pres.getImages().addImage(Files.readAllBytes(Paths.get("tiger.bmp")));
    } catch (IOException e) { }
    shape.getFillFormat().getPictureFillFormat().getPicture().setImage(picture);
    shape.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);

    // Aplicar efeitos 3D
    shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront);
    shape.getThreeDFormat().getCamera().setRotation(10, 20, 30);
    shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.Flat);
    shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
    shape.getThreeDFormat().setExtrusionHeight(150);
    shape.getThreeDFormat().getExtrusionColor().setColor(Color.GRAY);

    // Salvar apresentação
    pres.save("3D-Image.pptx", SaveFormat.Pptx);
} finally {
    if (pres != null) pres.dispose();
}

A seguir está a imagem resultante que obtemos após a aplicação de efeitos 3D.

Aplicar efeitos 3D a uma imagem no PowerPoint em Java

Obtenha uma licença gratuita

Você pode obter uma licença temporária gratuita para usar o Aspose.Slides for Java sem limitações de avaliação.

Conclusão

Neste artigo, você aprendeu como aplicar efeitos 3D no PowerPoint PPT/PPTX usando Java. Com a ajuda de exemplos de código, demonstramos como criar texto ou formas 3D e aplicar efeitos 3D a imagens em apresentações PPT ou PPTX. Você pode visitar a documentação para explorar mais sobre o Aspose.Slides for Java. Além disso, você pode postar suas perguntas ou dúvidas em nosso fórum.

Veja também