برش فایل PSD هنگام تبدیل به PNG

کد نمونه زیر نشان می‌دهد چگونه می‌توان فایل PSD را برش داده و هنگام تبدیل آن به PNG استفاده کرد.

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);
}