Packages

 

com.aspose.psd.fileformats.psd.layers.layerresources

Class LclrResource



  • public class LclrResource
    extends LayerResource

    Class LclrResource. This resource contains information about color of layer in layers' list is PS. It's only

    See Also:
    LayerResource
    Code example:

    An example of using Layer Sheet Color to visually highlight layers. For example you can update some layers in PSD and then highlight by color the layer which you want to attract attention.


                
    class LocalScopeExtension
    {
        void checkSheetColorsAndRerverse(Short[] sheetColors, PsdImage psdImage)
        {
            int layersCount = psdImage.getLayers().length;
            for (int layerIndex = 0; layerIndex < layersCount; layerIndex++)
            {
                Layer layer = psdImage.getLayers()[layerIndex];
                for (LayerResource layerResource : layer.getResources())
                {
                    if (!(layerResource instanceof LclrResource))
                    {
                        continue;
                    }
                
                    // The lcrl resource always presents in psd file resource list.
                    LclrResource resource = (LclrResource)layerResource;
                    if (resource.getColor() != sheetColors[layerIndex])
                    {
                        throw new Exception("Sheet Color has been read wrong");
                    }
                
                    // Reverse of style sheet colors. Set up of Layer color highlight.
                    resource.setColor(sheetColors[layersCount - layerIndex - 1]);
                    break;
                }
            }
        }
    }
    LocalScopeExtension $ = new LocalScopeExtension();
                
    String inPsdFilePath = "AllLclrResourceColors.psd";
    String outPsdFilePath = "AllLclrResourceColorsReversed.psd";
                
    // In the file colors of layers' highlighting are in this order
    Short[] sheetColors = new Short[] {
            SheetColorHighlightEnum.Red,
            SheetColorHighlightEnum.Orange,
            SheetColorHighlightEnum.Yellow,
            SheetColorHighlightEnum.Green,
            SheetColorHighlightEnum.Blue,
            SheetColorHighlightEnum.Violet,
            SheetColorHighlightEnum.Gray,
            SheetColorHighlightEnum.NoColor
    };
                
    // Load a PSD file containing a predefined LclrResource
    PsdImage psdImage = (PsdImage)Image.load(inPsdFilePath);
    try
    {
        $.checkSheetColorsAndRerverse(sheetColors, psdImage);
        psdImage.save(outPsdFilePath, new PsdOptions());
    }
    finally
    {
        psdImage.dispose();
    }
                
    // Load a just saved PSD file
    PsdImage psdImage1 = (PsdImage)Image.load(outPsdFilePath);
    try
    {
        // Reverse colors
        List<Short> sheetColorList = Arrays.asList(sheetColors);
        Collections.reverse(sheetColorList);
                
        $.checkSheetColorsAndRerverse(sheetColorList.toArray(new Short[0]), psdImage1);
    }
    finally
    {
        psdImage1.dispose();
    }
    

    • Field Detail

      • TypeToolKey

        public static final int TypeToolKey

        The type tool info key.

        See Also:
        Constant Field Values
    • Constructor Detail

      • LclrResource

        public LclrResource()

        Initializes a new instance of the LclrResource class.

      • LclrResource

        public LclrResource(short color)

        Initializes a new instance of the LclrResource class.

        Parameters:
        color - The color.
      • LclrResource

        public LclrResource(byte[] data)

        Initializes a new instance of the LclrResource class.

        Parameters:
        data - The resource data.
        Throws:
        PsdImageArgumentException - Invalid Lclr Resource value
    • Method Detail

      • getColor

        public final short getColor()

        Gets or sets the color of layer.

        Value: The color.
      • setColor

        public final void setColor(short value)

        Gets or sets the color of layer.

        Value: The color.
      • getKey

        public int getKey()

        Gets the layer resource key.

        Specified by:
        getKey in class LayerResource
      • getLength

        public int getLength()

        Gets the layer resource length in bytes.

        Specified by:
        getLength in class LayerResource
      • save

        public void save(StreamContainer streamContainer,
                         int psdVersion)

        Saves the resource to the specified stream container.

        Specified by:
        save in class LayerResource
        Parameters:
        streamContainer - The stream container to save to.
        psdVersion - The PSD version.