将 PSD 图像转换为光栅格式
Contents
[
Hide
]
使用 Aspose.PSD for Java,开发人员可以将 PSD 文件格式导出为任何受支持的光栅文件格式。本主题解释了加载现有 PSD 文件并将其导出为各种光栅文件格式的方法。
将 PSD 图像导出为各种光栅文件格式
下面提供的示例代码演示了如何将 PSD 转换为几种光栅文件格式。
This file contains 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
String dataDir = Utils.getDataDir(PSDToRasterImageFormats.class) + "Conversion/"; | |
String srcPath = dataDir + "sample.psd"; | |
String destName = dataDir + "export"; | |
// Load an existing PSD image as Image | |
try (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 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 + ".gif", gifOptions); | |
image.save(destName + ".jpeg", jpegOptions); | |
image.save(destName + ".jp2", jpeg2000Options); | |
} |