Add Watermark to PSD in C#

Adobe 广泛使用的 Photoshop 应用程序使用 PSD (Photoshop Document) 格式为其原始图像文件. 此格形式至关重要,以创建复杂的设计,如标志和小册子,往往包括多个层。 为了有效地保护您的图案,您可以编程 添加一个水标到一个 PSD 文件在 C#. 本文将指导您通过使用 Aspose.PSD 为 .NET API 的过程,一个强大的解决方案为 C# .NET 核心 PSD watermarking 和其他 PSD 图片操作任务

你会学到的

在这篇文章中,我们将讨论以下主题:

使用 C# Photoshop API 将水标添加到 PSD

要在 PSD 文件中编程添加文本或图像水标,我们将使用 ASPOSE.PSD 为 .NET API. 这个强大而易于使用的图书馆允许您操纵 Adobe Photoshop 文件格式而不需要 Adobe Photoshop 本身。 它是理想的 C# .NET 添加水标到 PSD 文档 任务,并支持各种操作,如压缩、旋转和多次播放。 支持的文件格式.

關鍵課程在 API

  • PsdImage:用于加载、编辑和保存PSD文件。
  • 图形:代表图形背景。
  • : 代表 PSD 文件中的每个层。

安装

你也可以 下载DLL 或者通过安装 NuGet:

PM> Install-Package Aspose.PSD

将文本水标添加到 PSD 使用 C#

要将文本水标添加到 PSD 文件中,请遵循以下步骤:

  • 将 PSD 文件作为 PsdImage 使用 Image 类。
  • 创建一个例子的 图形 类。
  • 为水标文本设置一个 对象。
  • 创建一个 SolidBrush 例子与您想要的颜色。
  • 定义线条调整。
  • 请使用 DrawString() 方法将文本转换为文本。
  • 使用 Save() 方法保存输出文件。

下面是一个代码样本显示 如何在 C# 中的 PSD 文件中添加文本水标:

// This code example shows how to add a text watermark to a PSD file
// Load a PSD file as an image and cast it into PsdImage
PsdImage psdImage = (PsdImage)Image.Load(@"C:\Files\SimplePSD.psd");
// Create graphics object to perform draw operations.
Graphics graphics = new Graphics(psdImage);
// Create font to draw watermark with.
Font font = new Font("Arial", 25.0f);
// Create a solid brush with color alpha set near to 0 to use watermarking effect.
SolidBrush brush = new SolidBrush(Color.FromArgb(80, 128, 128, 128));
// Specify string alignment to put watermark at the image center.
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
// Draw watermark using font, partly-transparent brush and rotation matrix at the image center.
graphics.DrawString("Sample Watermark Text", font, brush, new RectangleF(0, 0, psdImage.Width, psdImage.Height), sf);
// Export the image into PNG file format.
psdImage.Save(@"C:\Files\AddWatermark_output.png", new PngOptions());
Add Text Watermark to PSD using C#

Add Text Watermark to PSD using C#

要将输出保存为 PSD 文件,请使用下列代码剪辑:

psdImage.Save(@"C:\Files\AddWatermark_output.psd", new PsdOptions());

在 PSD 中创建 Diagonal Watermark 使用 C#

要在 PSD 文件中创建一个图形文本水标,请遵循以下步骤:

  • 将 PSD 文件作为 PsdImage 使用 Image 类。
  • 创建一个例子的 图形 类。
  • 为水标定义一个 对象。
  • 创建一个 SolidBrush 例子与您想要的颜色。
  • 指定转型矩阵,以旋转水标。
  • 设置链条调整。
  • 请使用 DrawString() 方法。
  • 使用 Save() 方法保存输出文件。

下面的代码样本显示 如何在 C# 中的 PSD 文件中添加图形文本水标:

// This code example shows how to add a diagonal text watermark to a PSD file
// Load a PSD file as an image and cast it into PsdImage
PsdImage psdImage = (PsdImage)Image.Load(@"C:\Files\SimplePSD.psd");
// Create graphics object to perform draw operations
Graphics graphics = new Graphics(psdImage);
// Create font to draw watermark with
Font font = new Font("Arial", 25.0f);
// Create a solid brush with color alpha set near to 0 to use watermarking effect
SolidBrush brush = new SolidBrush(Color.FromArgb(80, 128, 128, 128));
// Specify transform matrix to rotate watermark
graphics.Transform = new Matrix();
graphics.Transform.RotateAt(45, new PointF(psdImage.Width / 2, psdImage.Height / 2));
// Specify string alignment to put watermark at the image center
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
// Draw watermark using font, partly-transparent brush at the image center
graphics.DrawString("Sample Watermark Text", font, brush, new RectangleF(0, psdImage.Height / 2, psdImage.Width, psdImage.Height / 2), sf);
// Export the image into PNG file format
psdImage.Save(@"C:\Files\AddDiagnolWatermark_output.png", new PngOptions());
Create Diagonal Watermark in PSD using C#

Create Diagonal Watermark in PSD using C#

添加 Image Watermark 到 PSD 使用 C# {# 添加 Image-Watermark-to-PSD-using-CSharp}

要将图像作为水标添加到 PSD 文件中,请遵循以下步骤:

  • 将 PSD 文件作为 PsdImage 使用 Image 类。
  • 创建一个例子的 Layer 类。
  • 设置层的高度、宽度和不透明度。
  • 使用 AddLayer() 方法将层添加到 PSD。
  • 将水标图上传到层。
  • 呼叫 DrawImage() 方法,通过位置和水标图像层作为论点。
  • 使用 Save() 方法保存输出文件。

下面是一个代码样本显示 如何在 C# 中的 PSD 文件中添加图像水标:

// This code sample shows how to add an image watermark to a PSD file
// Load a PSD file into PsdImage object
PsdImage psdImage = (PsdImage)Image.Load(@"C:\Files\SimplePSD.psd");
// Add a new watermark layer
var baseLayer = new Layer();
baseLayer.Top = 200;
baseLayer.Bottom = 600;
baseLayer.Right = 600;
baseLayer.Opacity = 50;
// Add layer to PSD file
psdImage.AddLayer(baseLayer);
// Load a watermark image into a layer
FileStream ImageWatermarkFile = new FileStream(@"C:\Files\aspose_logo.png", FileMode.Open);
Layer ImageWatermarkLayer = new Layer(ImageWatermarkFile);
// Add image watermark to base layer
baseLayer.DrawImage(new Point(0, 200), ImageWatermarkLayer);
// Save final watermarked PSD file
psdImage.Save(@"C:\Files\ImageWatermarkedPSD.png", new PngOptions());
Add Image Watermark to PSD using C#

Add Image Watermark to PSD using C#

获得免费的临时许可证

你可以 获得免费的临时许可证 尝试 Aspose.PSD 为 .NET 没有任何评估限制。

结论

在这篇文章中,我们研究了如何:

  • 添加一个新的层到一个PSD图像。
  • 将文本或图像水标添加到 PSD。
  • 保存 PSD 作为 PNG 或 PSD 文件,使用 C#。

除了学习 如何在 C# 中的 PSD 文件中添加水标,您可以深入了解 ASPOSE.PSD 为 .NET 通过检查 人们在说什么 探索它的广泛功能. 如果你有任何问题,感到自由到达我们的 免费支持论坛.

使用 Aspose.PSD 插件,您可以有效地操纵 PSD 文件并在您的 C# .NET 应用程序中实施水标。 此指南提供您需要开始的基本知识 C# .NET 核心添加文本水标到 PSD, batch 水标 PSD 文件与 C# .NET 等. 无论您正在寻找 添加透明水标到 PSD 使用 C#编程添加图像水标到 PSD 在 C#,本教程作为您为 C# .NET 图书馆添加水标到 PSD 文件的全面资源。

使用 Aspose.PSD C# watermarking 教程,您现在有工具为您的 PSD 文件创建自定义解决方案,确保您的设计被有效保护。

More in this category