The ImagesApi interface provided by the Spire.Cloud.PowePoint API supports adding image to a PowerPoint document. This article will introduce how to do it with this interface.
import spire.cloud.powerpoint.sdk.ApiException;
import spire.cloud.powerpoint.sdk.Configuration;
import spire.cloud.powerpoint.sdk.api.ImagesApi;
import java.io.File;
public class AddImage {
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
// Create a Configuration object based on App ID, App Key and base Url
Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create an instance of ImagesApi
ImagesApi imagesApi = new ImagesApi(configuration);
// Specify the name of the input document
String name = "addSlideImage.pptx";
//Load an image
String imagePath = "C:/Users/Administrator/Desktop/sunset.jpg";
File imageData = new File(imagePath);
// Specify the original password of the input document, set it to null if there's none
String password = null;
// Specify the folder where the input document is stored, set it to null if there's none
String folder = "input";
// Store the document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Set the position of the image
int slideIndex = 0;
double x = 150;
double y = 80;
//Set the width and height of the image
double width = 500;
double height = 250;
//Add image to the PowerPoint document with the addSlideImage method
imagesApi.addSlideImage(name, slideIndex, x, y, width, height, imageData, password, folder, storage);
}
}