I want to convert the psd into a set of pictures instead of a long picture. Is there any good way?

https://tezign-assets.oss-cn-beijing.aliyuncs.com/5994c30dfff960c783cc12424580d3ad.psd

@zyx

Can you please share the details of your requirements that you want to achieve using Aspose.PSD. Please also share which API you are interested to use on your end (.NET or Java).

Like the psb shared above, I hope I can get a collection of pictures instead of a long picture, I use java

@zyx

Can you please what you mean by collection of pictures and on what basis you want to generate. The PSD comprised of layers. The API does allow export individual layer to image.

The other option, you can do is to perform the cropping of image and save a JPEG.

   string src = "InputPSDImage.psd";

            void SaveLayers(string dirPath, Layer[] layers)
            {
                Directory.CreateDirectory(dirPath);

                for (int i = 0; i < layers.Length; i++)
                {
                    var layer = layers[i];
                    if (layer is SectionDividerLayer)
                    {
                        var layerGroup = ((SectionDividerLayer)layer).GetRelatedLayerGroup();
                        string folderPath = Path.Combine(dirPath, layerGroup.Name);
                        SaveLayers(folderPath, layerGroup.Layers);

                        i += layerGroup.Layers.Length + 1;
                        continue;
                    }

                    string output = Path.Combine(dirPath, layer.DisplayName + ".png");
                    layer.Save(output, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                }
            };

            using (PsdImage image = (PsdImage)Aspose.PSD.Image.Load(src))
            {
                // How to save each layer as a separate PNG file.
                var layers = image.Layers;
                string folderPath = Path.Combine(Path.GetDirectoryName(src), Path.GetFileNameWithoutExtension(src));
                SaveLayers(folderPath, layers);

                // How to get the count of layers and know the layers name.
                List<string> layerNames = new List<string>();
                int totalLayersCount = layers.Length;
                int folderSectionsCount = 0;
                int layersCount = 0;

                foreach (var layer in layers)
                {
                    if (layer is LayerGroup || layer is SectionDividerLayer)
                    {
                        folderSectionsCount++;
                        continue;
                    }

                    layerNames.Add(layer.DisplayName);
                }
                layersCount = totalLayersCount - folderSectionsCount;
            }

this is .net but sorry i use java

@zyx

Please check the following Java implementation for the same.

static void SaveLayers(String dirPath, Layer[] layers) throws IOException
{
   Files.createDirectories(Paths.get(dirPath));

   for (int i = 0; i < layers.length; i++)
    {
        Layer layer = layers[i];
        if (layer instanceof SectionDividerLayer)
        {
            LayerGroup layerGroup = ((SectionDividerLayer)layer).getRelatedLayerGroup();
            String folderPath = dirPath+layerGroup.getName();
            SaveLayers(folderPath, layerGroup.getLayers());

            i += layerGroup.getLayers().length + 1;
            continue;
        }

        PngOptions options=new PngOptions();
        options.setColorType(PngColorType.TruecolorWithAlpha);

        String output = dirPath+ layer.getDisplayName() + ".png";
        layer.save(output, options);
    }
}

public static String getNameWithoutExtension(String file) {
   int dotIndex = file.lastIndexOf('.');
   return (dotIndex == -1) ? file : file.substring(0, dotIndex);
 }
public static void ExportLayerstoImage() throws IOException
{
    String src = "InputPSDImage.psd";

    PsdImage image = (PsdImage)com.aspose.psd.Image.load(src);

    // How to save each layer as a separate PNG file.
    Layer[] layers = image.getLayers();

    
    String folderPath = new File(src).getAbsoluteFile().getParent()+getNameWithoutExtension(src);

    SaveLayers(folderPath, layers);

    // How to get the count of layers and know the layers name.
    List<String> layerNames = new ArrayList<String>();
    int totalLayersCount = layers.length;
    int folderSectionsCount = 0;
    int layersCount = 0;

    for (Layer layer : layers)
    {
        if (layer instanceof LayerGroup || layer instanceof SectionDividerLayer)
        {
            folderSectionsCount++;
            continue;
        }

        layerNames.add(layer.getDisplayName());
    }
    layersCount = totalLayersCount - folderSectionsCount;

}

thank you,But you may have misunderstood what I mean, I want to get a set of pictures similar to the following

image.jpg (53.2 KB)
image.jpg (54.2 KB)

@zyx

You may need cropping feature support to get the desired images. Please use following documentation link sample to serve the purpose.