The Bounds property of the layer LayerGroup always has values 0 for X and Y

  • Detail:
    After reading the psd file with Psd23.5 (.net2.0), the Bounds property of the layer LayerGroup always has values 0 for X and Y, and the width and height are also incorrect (but only at the root level).

  • Here are the coordinates and width of the original psd named Maintain-Rect
    image.png (28.0 KB)

  • This is the information for breakpoint debugging
    psd-code-layergroup.png (72.4 KB)

@LoongDragon

To get the position of layer should be used PSD Layer Left and PSD Layer Top properties.

The PSD Image Bounds property just contains the size of the Layer in the Rectangle Type.

If the proposed soultion doesn’t work, could you please provide the input file and the code snippet to reproduce bug.

@Dmitriy.Sorokin 3ks for your reply!

  • The attribute lefit is also incorrect
    image.png (43.2 KB)

  • this is source file
    maintain_test.zip (33.2 KB)

  • this is source code , Only view after loading, nothing else is done
    public static void PsdToGUI()
    {
    string dir = @“E:\loong\git\my\unity\pandora\Artist”;
    var psdPath = EditorUtility.OpenFilePanel(“Psd”, dir, “psd”);

          if (string.IsNullOrEmpty(psdPath))
          {
              return;
          }
    
          using var image = Image.Load(psdPath);
          if (image is PsdImage psdImage)
          {
              var layers = psdImage.Layers;
          }
      }

@LoongDragon

Aspose.PSD doesn’t return the LayerGroup left and top, because there are can be some issues in calculation. Anyway, ability to get the real left and top in LayerGroup can be useful, so, I’ve created a feature request in our internal issue tracking system PSDNET-1585: Add ability to get the real LayerGroup Left and Top position.

You can track the issue status by its ID.

Also, please try the following code for the LayerGroup

using (PsdImage image = (PsdImage)Aspose.PSD.Image.Load(inputsd))
{
            var layers = image.Layers;

            for (int i = 0; i < layers.Length; i++)
            {
                var layer = layers[i];

                if (layer is LayerGroup)
                {
                    var group = (LayerGroup)layer;

                    var minLeft = int.MaxValue;
                    var minTop = int.MaxValue;
                    foreach (var innerLayer in group.Layers)
                    {
                        if (innerLayer is AdjustmentLayer || innerLayer.Bounds.IsEmpty)
                        {
                            continue;
                        }

                        minLeft = Math.Min(minLeft, innerLayer.Left);
                        minTop = Math.Min(minTop, innerLayer.Top);
                    }

                    Console.WriteLine($"Layer Group Position left = {minLeft}, top = {minTop}");
                    // To change the position, you need to change the position of inner layers
                }
            }

You can obtain https://helpdesk.aspose.com/ if you need support on a priority basis, along with the direct access to our Paid Support management team.

ok, 3ks for your reply