Šiame straipsnyje paaiškinama, kaip pridėti Vandens ženklo paveikslėlį į PowerPoint naudojant C# REST API. Sužinosite kaip padaryti nuotrauką vandens ženklu PowerPoint naudojant C# REST sąsają naudojant .NET pagrindu sukurtą SDK. Prieš pridedant jį kaip vandens ženklą prie pristatymo, jis bendrins informaciją, kad tinkintų paveikslėlį.
Būtina sąlyga
Atsisiųsti Aspose.Slides Cloud SDK for Dotnet to add an image watermark
Nustatykite C# projektą naudodami aukščiau pateiktą SDK, kad įterptumėte paveikslėlio vandens ženklą
Veiksmai, kaip įterpti vaizdo vandens ženklą į „PowerPoint“ naudojant C# REST API
- Inicijuoti Aspose SlidesApi su kliento kredencialais
- Įkelkite pristatymo failą į serverį naudodami UploadFile() metodą
- Perskaitykite vaizdo duomenis, kurie bus naudojami vandens ženklui, į baitų masyvą
- Naudodami PictureFrame klasę, nustatykite vaizdo rėmelį, kuriame bus vandens ženklo vaizdas
- Pridėkite vaizdą kaip vandens ženklą prie pristatymo naudodami CreateImageWatermark() metodą
- Atsisiųskite pakeistą pristatymą su vandens ženklu, pridėtu naudojant DownloadFile() metodą
- Išsaugokite atnaujintą pristatymą vietoje
Šie veiksmai aprašo, kaip paveikslėlį paversti vandens ženklu PowerPoint naudojant C# RESTful Service. Inicijuokite SlidesApi objektą, įkelkite pristatymą į serverį ir perskaitykite vandens ženklo vaizdą į baitų masyvą. Nustatykite PictureFrame objektą, kad nustatytumėte vandens ženklo parametrus ir įtrauktumėte jį į pristatymą naudodami CreateImageWatermark() metodą.
Kodas, skirtas pridėti vaizdo vandens ženklą „PowerPoint“ su C# .NET pagrindu veikiančiu API
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); | |
} | |
} | |
} | |
} |
Šis kodas parodo, kaip vaizdą paversti vandens ženklu programoje PowerPoint naudojant C# .NET pagrįstą API. Sukonfigūruokite paveikslėlio rėmelį, kad nustatytumėte vandens ženklo vaizdo padėtį iš viršutinio kairiojo kampo, jo dydį ir užpildymo formatą. Taip pat galite nustatyti DPI, apkarpyti paveikslėlius, plytelių poslinkį ir mastelį bei SVG duomenis.
Šis straipsnis mus išmokė kaip pažymėti vaizdą PowerPoint vandens ženklu naudojant C# Low Code API. Norėdami pašalinti vandens ženklą iš pristatymo, žr. straipsnį Pašalinkite vandens ženklą iš pristatymo naudodami C# REST API.