Spire.Cloud.PowerPoint provides the ImagesApi to handle images within a PowerPoint document. This article shows you how to add an image to a slide by using this API.
using System;
using System.IO;
using Spire.Cloud.Powerpoint.Sdk.Client;
using Spire.Cloud.Powerpoint.Sdk.Api;
namespace AddImage
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID and App Key
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create an ImageApi object
static ImagesApi imagesApi = new ImagesApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
String name = "sample.pptx";
//Specify the image path
string imagePath = "C:\\Users\\Administrator\\Desktop\\scenery.jpg";
//Load the image
System.IO.Stream imageData = new FileStream(imagePath, FileMode.Open);
//Specify the original password, set to null if there is no password
String password = null;
//Specify the folder where the source document is stored
String folder = "input";
//Use the default storage, set to null
String storage = null;
//Specify the slide index
int slideIndex = 0;
//Specify the x and y coordinate
double x = 50;
double y = 100;
//Specify the image size
double width = 500;
double height = 280;
//Call AddSlideImage method to insert image at the specified location
imagesApi.AddSlideImage(name, slideIndex, x, y, width, height, imageData, password, folder, storage);
}
}
}