이 단계별 자습서에서는 C#의 PSD에 이미지 워터마크를 추가하는 방법을 배웁니다. PSD 파일에 워터마크를 삽입하면 위조자가 문서의 불법 복사본을 만들기 더 어려워집니다.
C#에서 PSD에 이미지 워터마크를 추가하는 단계
- NuGet.org에서 Aspose.PSD for .NET 패키지 설치
- 필요한 네임스페이스를 사용하여 코드 작동
- SetLicense 메서드를 사용하여 .NET API용 Aspose.PSD 라이선스 설정
- Image 클래스를 사용하여 입력 PSD 파일을 PsdImage object 개체에 로드
- FileStream의 이미지를 사용하여 기본 Layer object 만들기
- 위에서 만든 PSD 이미지 개체에 기본 레이어 개체 추가
- 레이어 개체에 워터마크 이미지 로드
- 기본 레이어의 Draw watermark image
- 워터마크가 있는 최종 PSD 파일을 출력으로 저장
보시다시피 .NET용 Aspose.PSD를 사용하여 PSD file 워터마크를 빠르고 쉽게 작성할 수 있습니다. 시스템에 Photoshop이 설치되어 있지 않아도 됩니다. 그리고 아래에 제공된 코드를 사용하여 애플리케이션에 워터마크 기능을 추가할 수 있습니다.
C#에서 PSD에 이미지 워터마크를 추가하는 코드
using System; | |
using System.IO; | |
//Add reference to Aspose.PSD for .NET API | |
//Use following namespaces to add image watermark to PSD file | |
using Aspose.PSD; | |
using Aspose.PSD.FileFormats.Psd; | |
using Aspose.PSD.FileFormats.Psd.Layers; | |
using Aspose.PSD.Brushes; | |
using Aspose.PSD.ImageOptions; | |
namespace AddImageWatermarkToPSD | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Set Aspose license before adding image watermark to PSD | |
//using Aspose.PSD for .NET | |
Aspose.PSD.License AsposePSDLicense = new Aspose.PSD.License(); | |
AsposePSDLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
//Load a PSD file into PsdImage object | |
PsdImage PSDFileToAddImageWatermark = (PsdImage)Image.Load("PSDFileToAddImageWatermark.psd"); | |
//load a watermark image as into a layer | |
FileStream BaseLayerFile = new FileStream("BaseLayer.png", FileMode.Open); | |
Layer BaseLayer = new Layer(BaseLayerFile); | |
//add layer to PSD file | |
PSDFileToAddImageWatermark.AddLayer(BaseLayer); | |
//load a watermark image into a layer | |
FileStream ImageWatermarkFile = new FileStream("ImageWatermark.bmp", FileMode.Open); | |
Layer ImageWatermarkLayer = new Layer(ImageWatermarkFile); | |
//add image watermark to base layer | |
BaseLayer.DrawImage(new Point(0, 0), ImageWatermarkLayer); | |
//save final watermarked PSD file | |
PSDFileToAddImageWatermark.Save("ImageWatermarkedPSD.psd", new PsdOptions()); | |
} | |
} | |
} |
이 샘플에서는 C#에서 PSD에 이미지 워터마크를 추가하는 단계를 배웠습니다. 그러나 유사한 방식으로 C# 코드의 PSD에 텍스트 워터마크를 추가할 수도 있습니다. 이러한 단계는 별도의 방법 항목에 추가합니다. 이 C# 코드는 ASP.NET 웹 응용 프로그램, Windows 응용 프로그램 또는 서비스 등 모든 종류의 .NET 응용 프로그램과 함께 사용할 수 있습니다.