使用 C# 将 PSD 图像转换为光栅格式
Contents
[
Hide
]
使用 Aspose.PSD for .NET,开发者可以将 PSD 文件格式导出为任何支持的光栅文件格式。本主题解释了如何加载现有 PSD 文件并将其导出为各种光栅文件格式。
概述
Aspose.PSD 允许将 PSD 和 PSB 格式转换为 JPEG、JPEG2000、PNG、TIFF、PDF、GIF 和 BMP 格式
您可以使用 Aspose.PSD 在服务器上转换 PSD 文件,无需 Photoshop。这是 Adobe Photoshop 脚本的良好替代品,因为 Adobe 的 EULA 禁止在服务器上使用应用程序并更改其用户界面。但是使用 PSD 格式 SDK,您可以批量转换 PSD 文件。您的 PSD 格式导出可以通过只读模式实现像素完美,或者您可以更改图层、文字、效果,然后导出。
将 PSD 导出为光栅格式的具体示例
将 PSD 图像导出为各种光栅文件格式
以下示例代码演示了如何将 PSD 转换为多个光栅文件格式。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string srcPath = dataDir + @"sample.psd"; | |
string destName = dataDir + @"export"; | |
// Load an existing PSD image as Image | |
using (Image image = Image.Load(srcPath)) | |
{ | |
// Create an instance of PngOptions class | |
PngOptions pngOptions = new PngOptions(); | |
// Create an instance of BmpOptions class | |
BmpOptions bmpOptions = new BmpOptions(); | |
// Create an instance of TiffOptions class | |
TiffOptions tiffOptions = new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.Default); | |
// Create an instance of GifOptions class | |
GifOptions gifOptions = new GifOptions(); | |
// Create an instance of JpegOptions class | |
JpegOptions jpegOptions = new JpegOptions(); | |
// Create an instance of Jpeg2000Options class | |
Jpeg2000Options jpeg2000Options = new Jpeg2000Options(); | |
// Call the save method, provide output path and export options to convert PSD file to various raster file formats. | |
image.Save(destName + ".png", pngOptions); | |
image.Save(destName + ".bmp", bmpOptions); | |
image.Save(destName + ".tiff", tiffOptions); | |
image.Save(destName + ".gif", gifOptions); | |
image.Save(destName + ".jpeg", jpegOptions); | |
image.Save(destName + ".jp2", jpeg2000Options); | |
} |