Artikel ini memandu tentang cara menambahkan Gambar Watermark di PowerPoint dengan C# REST API. Anda akan mempelajari cara menjadikan foto sebagai tanda air di PowerPoint dengan Antarmuka C# REST menggunakan SDK berbasis .NET. Ini akan membagikan detail untuk menyesuaikan gambar sebelum menambahkannya sebagai tanda air ke presentasi.
Prasyarat
Unduh Aspose.Slides Cloud SDK for Dotnet to add an image watermark
Siapkan proyek C# dengan SDK di atas untuk menyisipkan tanda air gambar
Langkah-langkah Menyisipkan Watermark Gambar di PowerPoint dengan C# REST API
- Inisialisasi Aspose SlidesApi dengan kredensial klien
- Unggah file presentasi ke server menggunakan metode UploadFile()
- Membaca data gambar yang akan digunakan untuk watermark ke dalam array byte
- Siapkan bingkai gambar yang akan menampung gambar watermark menggunakan kelas PictureFrame
- Tambahkan gambar sebagai watermark ke presentasi menggunakan metode CreateImageWatermark()
- Unduh presentasi yang dimodifikasi dengan tanda air yang ditambahkan dengan metode DownloadFile()
- Simpan presentasi yang diperbarui secara lokal
Langkah-langkah ini menjelaskan cara membuat gambar menjadi tanda air di PowerPoint dengan C# RESTful Service. Inisialisasi objek SlidesApi, unggah presentasi ke server, dan baca gambar tanda air ke dalam array byte. Siapkan objek PictureFrame untuk mengatur parameter tanda air dan menambahkannya ke presentasi menggunakan metode CreateImageWatermark().
Kode untuk Menambahkan Tanda Air Gambar di PowerPoint dengan API berbasis C# .NET
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); | |
} | |
} | |
} | |
} |
Kode ini menunjukkan cara membuat gambar menjadi tanda air di PowerPoint dengan API berbasis C# .NET. Konfigurasikan bingkai foto untuk mengatur posisi gambar watermark dari pojok kiri atas, ukurannya dan format isiannya. Anda juga dapat mengatur DPI, memotong gambar, offset dan skala ubin, serta data SVG.
Artikel ini telah mengajari kita cara memberi tanda air pada gambar di PowerPoint dengan C# Low Code API. Untuk menghapus watermark dari presentasi, lihat artikel Hapus Tanda Air dari Presentasi dengan C# REST API.