この記事に従って、C# REST API を使用して PowerPoint で画像を背景として使用 します。.NET ベースの Cloud SDK を使用して、C# REST インターフェイスで PowerPoint の背景デザインを変更 する方法を学習します。スライドの背景画像をカスタマイズするためのさまざまなオプションについて説明します。
前提条件
ダウンロード Aspose.Slides Cloud SDK for Dotnet for setting slides background
上記のSDKを使用してC#プロジェクトをセットアップし、画像を背景として設定します。
C# ローコード API を使用して PowerPoint の背景を設定する手順
- スライドの背景を設定するためのSlidesApiオブジェクトを作成する
- ソースのPowerPointプレゼンテーションを一意の名前でクラウドストレージにアップロードします
- 画像ファイルのデータをバイト配列に読み込み、Base64文字列に変換します。
- SlideBackgroundオブジェクトを作成し、背景画像パラメータを設定するための塗りつぶし形式を設定します。
- SetBackground() メソッドを呼び出して PowerPoint スライドの背景を設定します
- 背景を設定した後、更新されたPowerPointプレゼンテーションをダウンロードします
これらの手順では、C# .NET ベースの API を使用して PowerPoint プレゼンテーションの背景を設定する方法について説明します。SlidesApi オブジェクトを作成し、プレゼンテーションをクラウド ストレージにアップロードし、画像データを読み取って Base 64 文字列に変換し、SlideBackground オブジェクトで使用して FillFormat を設定します。最後に、SetBackground() メソッドを呼び出して画像を背景として追加し、出力ファイルをディスクにダウンロードします。
C# Low Code API を使用して PPT 背景を追加するコード
using Aspose.Slides.Cloud.Sdk; | |
using Aspose.Slides.Cloud.Sdk.Model; | |
using System; | |
using System.IO; | |
namespace AsposeKBExamples | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // For setting background | |
{ | |
SlidesApi api = new SlidesApi("ClientID", "ClientSecret"); | |
string presFileName = "InputPresentation.pptx"; | |
FilesUploadResult uploadResult = api.UploadFile(presFileName, new MemoryStream(File.ReadAllBytes(presFileName))); | |
var backgroundImage = File.ReadAllBytes("BackgroundImage.png"); | |
var pictureBackground = new SlideBackground(); | |
PictureFill pictureFill = new PictureFill();//For customization of the background image | |
pictureFill.Base64Data = Convert.ToBase64String(backgroundImage);; | |
pictureFill.PictureFillMode = PictureFill.PictureFillModeEnum.Stretch; | |
pictureBackground.FillFormat = pictureFill; | |
var currentBackground = api.SetBackground(presFileName, 1, pictureBackground); | |
Stream stream = api.DownloadFile(presFileName); | |
FileStream outputFileStream = new FileStream("OutputPresentation.pptx", FileMode.Create, FileAccess.Write);//File stream for output presentation | |
stream.CopyTo(outputFileStream);//Copy data to file stream | |
} | |
} | |
} |
このコードは、C# Low Code API を使用してプレゼンテーション スライドの背景を設定する方法を示しています。画像の塗りつぶしモード、グロー、内側の影、外側の影、ソフト エッジ、反射など、画像のさまざまなプロパティを設定できます。アップロードされた PowerPoint プレゼンテーションが保護されている場合は、パスワードを入力してください。
この記事では、C# REST インターフェイスを使用して PPT の背景画像を設定する方法を説明しました。プレゼンテーション内または別のプレゼンテーションにスライドをコピーする場合は、記事 C# REST API を使用して PowerPoint スライドをコピーする を参照してください。