이 문서에서는 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# Low Code API를 사용하여 PowerPoint에서 이미지에 워터마킹하는 방법을 설명했습니다. 프레젠테이션에서 워터마크를 제거하려면 C# REST API를 사용하여 프레젠테이션에서 워터마크 제거 문서를 참조하세요.