Cắt Ghép Tệp PSD Khi Chuyển Đổi Sang PNG

Cắt Ghép Tệp PSD Khi Chuyển Đổi Sang PNG

Bên dưới là đoạn mã minh họa cung cấp cho việc cắt ghép hình ảnh PSD trong quá trình chuyển đổi sang 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);
}