PSDファイルをPNGに変換する際の切り取り
Contents
[
Hide
]
Aspose.PSD for Javaを使用すると、開発者はPSD画像をラスタ形式に変換しながら画像を切り取ることができます。このトピックでは、既存の画像を読み込み、切り取り、ラスタ形式に変換するアプローチについて説明します。
PSDファイルをPNGに変換する際の切り取り
以下に示すサンプルコードは、PSD画像をPNGに変換する際にその画像を切り取る方法を示しています。
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
String dataDir = Utils.getDataDir(CropPSDFile.class) + "Conversion/"; | |
// Implement correct Crop method for PSD files. | |
String sourceFileName = dataDir + "1.psd"; | |
String exportPathPsd = dataDir + "CropTest.psd"; | |
String exportPathPng = dataDir + "CropTest.png"; | |
try (RasterImage image = (RasterImage) Image.load(sourceFileName)) { | |
image.crop(new Rectangle(10, 30, 100, 100)); | |
image.save(exportPathPsd, new PsdOptions()); | |
PngOptions options = new PngOptions(); | |
options.setColorType(PngColorType.TruecolorWithAlpha); | |
image.save(exportPathPng, options); | |
} |