I am having problems compiling sample code for extracting layers from a PSD.
I downloaded the “total” package and pulled out these two JARs:
- aspose-imaging-22.3-jdk16.jar
- aspose-psd-21.7-jdk16.jar
I run this command to compile (on MacOS):
javac -cp “.:*” Layers.java
I am getting this error:
Layers.java:21: error: no suitable method found for save(String,PngOptions)
psdImage.getLayers()[i].save(String.format(“layer_out{0}.png”, i + 1), pngOptions);
^
method Image.save(RandomAccessFile,ImageOptionsBase) is not applicable
(argument mismatch; String cannot be converted to RandomAccessFile)
method Image.save(OutputStream,ImageOptionsBase) is not applicable
(argument mismatch; String cannot be converted to OutputStream)
method Layer.save(String,ImageOptionsBase) is not applicable
(argument mismatch; PngOptions cannot be converted to ImageOptionsBase)
method Layer.save(String,boolean) is not applicable
(argument mismatch; PngOptions cannot be converted to boolean)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
Here is my code:
import com.aspose.psd.fileformats.psd.PsdImage;
import com.aspose.psd.Image;
import com.aspose.imaging.imageoptions.PngOptions;
import com.aspose.imaging.fileformats.png.PngColorType;
class Layers {
public static void main(String[] args) {
System.out.println("hi");
// Load a PSD file as an image and caste it into PsdImage
PsdImage psdImage = (PsdImage) Image.load("test.psd");
// Create an instance of PngOptions class
PngOptions pngOptions = new PngOptions();
pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
// Loop through the list of layers
for (int i = 0; i < psdImage.getLayers().length; i++) {
// Convert and save the layer to PNG file format.
psdImage.getLayers()[i].save(String.format("layer_out{0}.png", i + 1), pngOptions);
}
}
}
Why doesn’t it like the save command?