Packages

 

com.aspose.psd.fileformats.psd.layers.layereffects

Class GradientOverlayEffect

  • java.lang.Object
    • com.aspose.psd.fileformats.psd.layers.layereffects.GradientOverlayEffect
  • All Implemented Interfaces:
    ILayerEffect


    public class GradientOverlayEffect
    extends Object
    implements ILayerEffect

    Gradient Layer effect

    Code example:

    An example of applying the gradient overlay effect for an image layer.


                
    String inPsdFilePath = "psdnet256.psd";
    String outPsdFilePath = "psdnet256.psd_output.psd";
                
    // Support layer effects, if any
    PsdLoadOptions psdLoadOptions = new PsdLoadOptions();
    psdLoadOptions.setLoadEffectsResource(true);
                
    // Load a PSD file containing an image
    PsdImage psdImage = (PsdImage)Image.load(inPsdFilePath, psdLoadOptions);
    try
    {
        BlendingOptions layerBlendOptions = psdImage.getLayers()[1].getBlendingOptions();
                
        // Search GradientOverlayEffect in a layer
        GradientOverlayEffect gradientOverlayEffect = null;
        for (ILayerEffect effect : layerBlendOptions.getEffects())
        {
            gradientOverlayEffect = (GradientOverlayEffect)effect;
            if (gradientOverlayEffect != null)
            {
                break;
            }
        }
                
        if (gradientOverlayEffect == null)
        {
            // Create a new GradientOverlayEffect if it not exists
            gradientOverlayEffect = layerBlendOptions.addGradientOverlay();
        }
                
        // Add a bit of transparency to the effect
        gradientOverlayEffect.setOpacity((byte)200);
                
        // Change the blend mode of gradient effect
        gradientOverlayEffect.setBlendMode(BlendMode.Hue);
                
        // Get GradientFillSettings object to configure gradient overlay settings
        GradientFillSettings settings = gradientOverlayEffect.getSettings();
                
        // Set a new gradient with two colors
        settings.setColorPoints(new IGradientColorPoint[]
                {
                        new GradientColorPoint(Color.getGreenYellow(), 0, 50),
                        new GradientColorPoint(Color.getBlueViolet(), 4096, 50),
                });
                
        // Set an inclination of the gradient at an angle of 80 degrees
        settings.setAngle(80);
                
        // Scale gradient effect up to 150%
        settings.setScale(150);
                
        // Set type of gradient
        settings.setGradientType(GradientType.Linear);
                
        // Make the gradient opaque by setting the opacity to 100% at each transparency point
        settings.getTransparencyPoints()[0].setOpacity(100);
        settings.getTransparencyPoints()[1].setOpacity(100);
                
        psdImage.save(outPsdFilePath);
    }
    finally
    {
        psdImage.dispose();
    }
    

    • Method Detail

      • getSettings

        public final GradientFillSettings getSettings()

        Gets or sets the settings.

        Value: The settings.
      • setSettings

        public final void setSettings(GradientFillSettings value)

        Gets or sets the settings.

        Value: The settings.
      • getBlendMode

        public final long getBlendMode()

        Gets or sets the blend mode.

        Value: The blend mode.
        Specified by:
        getBlendMode in interface ILayerEffect
      • setBlendMode

        public final void setBlendMode(long value)

        Gets or sets the blend mode.

        Value: The blend mode.
        Specified by:
        setBlendMode in interface ILayerEffect
        Code example:

        An example of changing the blending mode for a gradient overlay effect.


                    
        String inPsdFilePath = "psdnet585.psd";
        String outPsdFilePath = "out_psdnet585.psd";
                    
        // Load a PSD file containing an image layer
        PsdImage psdImage = (PsdImage)Image.load(inPsdFilePath);
        try
        {
            GradientOverlayEffect gradientOverlayEffect =
                    psdImage.getLayers()[1].getBlendingOptions().addGradientOverlay();
                    
            // Change the blend mode for the gradient overlay effect
            gradientOverlayEffect.setBlendMode(BlendMode.Subtract);
                    
            // Save a modified copy of loaded PSD file on the path
            psdImage.save(outPsdFilePath);
        }
        finally
        {
            psdImage.dispose();
        }
        

      • isVisible

        public final boolean isVisible()

        Gets or sets a value indicating whether this instance is visible.

        Value: true if this instance is visible; otherwise, false.
        Specified by:
        isVisible in interface ILayerEffect
      • setVisible

        public final void setVisible(boolean value)

        Gets or sets a value indicating whether this instance is visible.

        Value: true if this instance is visible; otherwise, false.
        Specified by:
        setVisible in interface ILayerEffect
      • getOpacity

        public final byte getOpacity()

        Gets or sets the opacity.

        Value: The opacity.
        Specified by:
        getOpacity in interface ILayerEffect
      • setOpacity

        public final void setOpacity(byte value)

        Gets or sets the opacity.

        Value: The opacity.
        Specified by:
        setOpacity in interface ILayerEffect