Java graphics rendering in the PPT

Microsoft PowerPoint can support the insertion of various types of graphical and may be provided in the slide fill pattern, line color, pattern size, location and so on. The following methods for drawing graphics to demonstrate the PPT in the Java programming.

工具:Free Spire.Presentation for Java 

 

Jar file import method 1 : by downloading the official website .

Step1 : Create a Directory in the program directory named lib; and the control packet Spire.Presentation.jar (lib available in the decompressed file in the control packet) is directly copied in this directory.

 

Step2: Spire.Presentation.jar the selected file copy, right click and select "Add as library". Complete reference.


 

Jar file import Method 2 : by Maven repository installation. Specific can be found in this article example

 

Java code sample (for reference)

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;

public class CreateShapes_PPT {

    public static void main(String[] args) throws Exception {

        // Create PowerPoint documents
        Presentation presentation = new Presentation();

        // Add a triangle, and solid fill disposed
        IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.TRIANGLE, new Rectangle2D.Double(115, 130, 100, 100));
        shape.getFill().setFillType(FillFormatType.SOLID);
        shape.getFill().getSolidColor().setColor(Color.orange);
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        // add an oval, and set the picture fill
        shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.ELLIPSE, new Rectangle2D.Double(290, 130, 150, 100));
        shape.getFill().setFillType(FillFormatType.PICTURE);
        shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        BufferedImage image = ImageIO.read(new File("logo.png"));
        shape.getFill().getPictureFill().getPicture().setEmbedImage(presentation.getImages().append(image));
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        // Add a heart-shaped, and disposed hatch
        shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.HEART, new Rectangle2D.Double(515, 130, 130, 100));
        shape.getFill().setFillType(FillFormatType.PATTERN);
        shape.getFill().getPattern().setPatternType(PatternFillType.LARGE_GRID);
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        // add a five-pointed star, and set the gradient fill
        shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.FIVE_POINTED_STAR, new Rectangle2D.Double(115, 300, 115, 115));
        shape.getFill().setFillType(FillFormatType.GRADIENT);
        shape.getFill().getGradient().getGradientStops().append(0, KnownColors.RED);
        shape.getFill().getGradient().getGradientStops().append(1, KnownColors.LIGHT_SALMON);
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        // Add a rectangle, and set the gradient fill
        shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.HEXAGON, new Rectangle2D.Double(290, 300, 140, 125));
        shape.getFill().setFillType(FillFormatType.GRADIENT);
        shape.getFill().getGradient().getGradientStops().append(0, KnownColors.LIGHT_PINK);
        shape.getFill().getGradient().getGradientStops().append(1, KnownColors.LIGHT_SKY_BLUE);
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        // add an up arrow, and set the gradient fill
        shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.DOUBLE_WAVE, new Rectangle2D.Double(515, 300, 130, 100));
        shape.getFill().setFillType(FillFormatType.GRADIENT);
        shape.getFill().getGradient().getGradientStops().append(1f, KnownColors.OLIVE);
        shape.getFill().getGradient().getGradientStops().append(0, KnownColors.POWDER_BLUE);
        shape.getShapeStyle().getLineColor().setColor(Color.white);
        
        // save the document
        presentation.saveToFile("AddShapes.pptx", FileFormat.PPTX_2010);
    }
}

 Graphics rendering effects:


 

Note:

 

1. Many library supports graphical species, such as the following figure:


 

2. The above library environment can not install Microsoft PowerPoint

 

 

(This article End)

Guess you like

Origin miaonly.iteye.com/blog/2442140