本简短主题指导在 C# 中编辑 PSD 文件。了解配置详细信息,获取包含步骤的列表以及运行代码片段,以使用 C#** 开发 **PSD 照片编辑器。本文将解释在 PSD 文件中添加/编辑不同图层的不同选项。
使用 C# 无需 Photoshop 即可编辑 PSD 的步骤
- 通过安装 Aspose.PSD for .NET 来编辑 PSD 文件来准备您的系统
- 创建 Image 类的对象来加载源 PSD 文件
- 使用 AddTextLayer 方法添加新的文本层
- 选择特定图层并对其进行修改
- 保存更新和编辑的 PSD 图像
按照上述步骤使用 C# 无需 Photoshop 即可编辑 PSD 文件。该过程将从磁盘或内存流加载源 PSD 图像文件开始。接下来,添加新的文本图层并更改特定图层的属性。最后,保存输出编辑的 PSD 图像。
用 C# 开发 PSD 文件编辑器的代码
using Aspose.PSD; | |
using System; | |
using System.Linq; | |
class Program | |
{ | |
static void Main(string[] args) // Update PSD in C# | |
{ | |
new License().SetLicense("License.lic"); | |
// Load an existing PSD | |
var psdImage = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load("sample.psd"); | |
// Add a new text layer | |
var layer1 = psdImage.AddTextLayer("Hello", new Aspose.PSD.Rectangle(0, 0, 120, 50)); layer1.Left = 10; | |
layer1.Top = 25; | |
// Change the properties of a specific layer | |
var layer = psdImage.Layers.FirstOrDefault(x => x.DisplayName == "sample"); if (layer != null) | |
{ | |
layer.IsVisible = false; | |
} | |
// Save the edited PSD | |
psdImage.Save("edited.psd"); | |
Console.WriteLine("PSD updated successfully"); | |
} | |
} |
上面的示例代码展示了在 C# 中编辑 PSD 的基本工作流程。使用 Aspose.PSD.FileFormats.Psd 命名空间中的 PsdImage 类加载源 PSD 图像。接下来,它调用 AddTextLayer 方法将文本附加到 PSD 文件。此外,您可以即兴编写代码,例如旋转 PSD 文件、调整大小、合并图层以及裁剪 PSD 以根据您的要求编辑 PSD 图像。
本文教我们用 C#* 创建一个 *PSD 图像编辑器。但是,如果您想将 AI 图像转换为 TIFF,请阅读有关 如何在 C# 中将 AI 转换为 TIFF 的文章。