รูปภาพลายน้ำใน PowerPoint พร้อม C# REST API

บทความนี้จะแนะนำวิธีเพิ่ม ภาพลายน้ำใน PowerPoint ด้วย C# REST API คุณจะได้เรียนรู้วิธี วิธีสร้างลายน้ำให้กับภาพถ่ายใน PowerPoint ด้วยอินเทอร์เฟซ C# REST โดยใช้ SDK ที่ใช้ .NET โดยจะแชร์รายละเอียดเพื่อปรับแต่งรูปภาพก่อนที่จะเพิ่มเป็นลายน้ำในงานนำเสนอ

ข้อกำหนดเบื้องต้น

ขั้นตอนในการแทรกลายน้ำรูปภาพใน PowerPoint ด้วย C # REST API

  1. เริ่มต้น Aspose SlidesApi ด้วยข้อมูลประจำตัวไคลเอ็นต์
  2. อัปโหลดไฟล์การนำเสนอไปยังเซิร์ฟเวอร์โดยใช้เมธอด UploadFile()
  3. อ่านข้อมูลรูปภาพที่จะใช้สำหรับลายน้ำลงในอาร์เรย์ไบต์
  4. ตั้งค่ากรอบรูปภาพที่จะเก็บภาพลายน้ำโดยใช้คลาส PictureFrame
  5. เพิ่มรูปภาพเป็นลายน้ำในงานนำเสนอโดยใช้วิธี CreateImageWatermark()
  6. ดาวน์โหลดงานนำเสนอที่แก้ไขแล้วโดยมีลายน้ำเพิ่มด้วยวิธี DownloadFile()
  7. บันทึกการนำเสนอที่อัปเดตในเครื่อง

ขั้นตอนเหล่านี้อธิบาย วิธีทำให้รูปภาพเป็นลายน้ำใน PowerPoint ด้วย C# RESTful Service เริ่มต้นวัตถุ SlidesApi อัปโหลดงานนำเสนอไปยังเซิร์ฟเวอร์ และอ่านภาพลายน้ำลงในอาร์เรย์ไบต์ ตั้งค่าออบเจ็กต์ PictureFrame เพื่อตั้งค่าพารามิเตอร์ลายน้ำและเพิ่มลงในงานนำเสนอโดยใช้เมธอด CreateImageWatermark()

รหัสเพื่อเพิ่มลายน้ำรูปภาพใน PowerPoint ด้วย API ที่ใช้ 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);
}
}
}
}

รหัสนี้สาธิต วิธีทำให้รูปภาพเป็นลายน้ำใน PowerPoint ด้วย API ที่ใช้ C# .NET กำหนดค่ากรอบรูปเพื่อกำหนดตำแหน่งรูปภาพลายน้ำจากมุมซ้ายบน ขนาด และรูปแบบการเติม คุณยังสามารถตั้งค่า DPI, ครอบตัดรูปภาพ, ออฟเซ็ตและมาตราส่วนของไทล์ และข้อมูล SVG ได้อีกด้วย

บทความนี้ได้สอนเรา วิธีใส่ลายน้ำรูปภาพใน PowerPoint ด้วย C# Low Code API หากต้องการลบลายน้ำออกจากงานนำเสนอ โปรดดูบทความ ลบลายน้ำออกจากการนำเสนอด้วย C# REST API

 ไทย