この記事では、C# REST API** を使用して **ウォーターマーク画像を PowerPoint に追加する方法について説明します。 .NET ベースの SDK を使用して、C# REST インターフェイスを使用して PowerPoint で写真にウォーターマークを作成する方法を学習します。画像をウォーターマークとしてプレゼンテーションに追加する前に、画像をカスタマイズするための詳細が共有されます。
前提条件
ダウンロード Aspose.Slides Cloud SDK for Dotnet to add an image watermark
画像の透かしを挿入するために上記の SDK を使用して C# プロジェクトをセットアップします
C# REST API を使用して PowerPoint に画像透かしを挿入する手順
- クライアントの資格情報を使用して Aspose SlidesApi を初期化する
- UploadFile() メソッドを使用して、プレゼンテーション ファイルをサーバーにアップロードします。
- ウォーターマークに使用する画像データをバイト配列に読み込みます。
- PictureFrame クラスを使用して、透かし画像を保持する画像フレームを設定します。
- CreateImageWatermark() メソッドを使用して、画像をウォーターマークとしてプレゼンテーションに追加します
- DownloadFile() メソッドを使用して、ウォーターマークが追加された変更されたプレゼンテーションをダウンロードします。
- 更新されたプレゼンテーションをローカルに保存する
これらの手順では、C# RESTful サービスを使用して PowerPoint で画像に透かしを作成する方法 について説明します。 SlidesApi オブジェクトを初期化し、プレゼンテーションをサーバーにアップロードし、透かし画像をバイト配列に読み取ります。 PictureFrame オブジェクトをセットアップしてウォーターマーク パラメーターを設定し、CreateImageWatermark() メソッドを使用してプレゼンテーションに追加します。
C# .NET ベースの API を使用して PowerPoint に画像透かしを追加するコード
using Aspose.Slides.Cloud.Sdk; | |
using Aspose.Slides.Cloud.Sdk.Model; | |
using System; | |
using System.IO; | |
namespace PresentationProcessor | |
{ | |
// This class demonstrates how to modify a slide deck by adding an image watermark. | |
class ModifySlide | |
{ | |
static void Main(string[] args) | |
{ | |
// Initialize the Aspose Slides API with client credentials (replace with actual credentials) | |
var slideService = new SlidesApi("ID", "KEY"); | |
// Define the name of the presentation file to be modified | |
string inputFileName = "OriginalSlides.pptx"; | |
// Specify the local path of the image that will be used as a watermark | |
string imagePath = "NewImage.png"; | |
// Upload the presentation file to the server | |
var uploadResult = slideService.UploadFile(inputFileName, new MemoryStream(File.ReadAllBytes(inputFileName))); | |
// Read the image data that will be used for the watermark | |
byte[] imageContent = File.ReadAllBytes(imagePath); | |
// Set up the image frame that will hold the watermark image | |
PictureFrame newImageFrame = new PictureFrame | |
{ | |
X = 50, // Horizontal position of the watermark (from the left) | |
Y = 50, // Vertical position of the watermark (from the top) | |
Width = 800, // Width of the watermark image | |
Height = 450, // Height of the watermark image | |
PictureFillFormat = new PictureFill | |
{ | |
Base64Data = Convert.ToBase64String(imageContent), // The image data encoded in base64 | |
PictureFillMode = PictureFill.PictureFillModeEnum.Stretch, // Image will stretch to fit the frame | |
} | |
}; | |
// Add the image as a watermark to the presentation | |
slideService.CreateImageWatermark(inputFileName, null, newImageFrame); | |
// Download the modified presentation with the watermark added | |
Stream modifiedFileStream = slideService.DownloadFile(inputFileName); | |
// Save the updated presentation locally | |
using (var localFileStream = new FileStream("UpdatedSlideDeck.pptx", FileMode.Create, FileAccess.Write)) | |
{ | |
// Copy the content of the downloaded file stream to the local file stream | |
modifiedFileStream.CopyTo(localFileStream); | |
} | |
} | |
} | |
} |
このコードは、C# .NET ベースの API を使用して PowerPoint で画像に透かしを作成する方法 を示しています。画像フレームを設定して、左上隅からの透かし画像の位置、サイズ、塗りつぶし形式を設定します。 DPI、画像の切り抜き、タイルのオフセットとスケール、SVG データを設定することもできます。
この記事では、C# ロー コード API を使用して PowerPoint の画像に透かしを入れる方法 を説明しました。プレゼンテーションからウォーターマークを削除するには、記事 C# REST API を使用してプレゼンテーションからウォーターマークを削除する を参照してください。