RESOLVED: Extract layers sample code fails to compile - no suitable method found for save

I am having problems compiling sample code for extracting layers from a PSD.

I downloaded the “total” package and pulled out these two JARs:

  1. aspose-imaging-22.3-jdk16.jar
  2. 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?

@nosajis,
The problem is in using the incorrect namespace,
to work with PsdImage you should use the types from the PSD namespace (com.aspose.psd) but you use types from the Imaging namespace (com.aspose.imaging).

To solve the problem and use the PSD imports, try to:

Replace these import references:
import com.aspose.imaging.imageoptions.PngOptions;
import com.aspose.imaging.fileformats.png.PngColorType;

by these (correct import references):
import com.aspose.psd.imageoptions.PngOptions;
import com.aspose.psd.fileformats.png.PngColorType;

Perfect, worked, thank you.