**— title: Using Layer Effects in PSD files weight: 100 type: docs description: Example of using Layer Effects in the Aspose.PSD for Java keywords: [drop shadow, color overlay, inner glow, outer glow, psd api, java, code sample] url: java/layer-effects/
Overview
In Aspose.PSD for Java, you can apply various effects to layers to enhance the visual appearance of your images. These effects are facilitated through the BlendingOptions class, which offers methods to incorporate different effects such as stroke, inner shadow, drop shadow, gradient overlay, color overlay, pattern overlay, and outer glow.
To illustrate the process of applying effects to layers, let’s outline the steps involved:
-
Stroke: This effect entails adding a gradient stroke to a layer, specifying parameters like stroke size, gradient color points, and transparency points.
-
Inner Shadow: Involves adding an inner shadow to a layer, defining attributes such as shadow angle and color.
-
Drop Shadow: This effect entails adding a drop shadow to a layer, specifying parameters such as shadow angle and color.
-
Gradient Overlay: Adds a gradient overlay to a layer, defining gradient color points and transparency points.
-
Color Overlay: Incorporates a color overlay onto a layer, specifying the color and opacity of the overlay.
-
Pattern Overlay: Entails adding a pattern overlay to a layer, defining attributes such as pattern data, width, and height.
-
Outer Glow: Adds an outer glow to a layer, specifying parameters like glow size and fill color.
-
After applying the desired effects to the layers, you can save the modified image in various formats.
-
This description outlines the fundamental process of applying effects to layers using Aspose.PSD for Java. You can further customize these effects by adjusting their respective parameters and properties. The library offers a range of options and settings to create intricate and visually appealing effects.
-
Explore the library’s documentation for comprehensive details and examples on applying effects to layers in Aspose.PSD for Java.
Please check full example.
Example
public void layerEffectsFullTest() { | |
String source = "/ShowCases/nines.psd"; | |
String resultOrig = "nines_orig.png"; | |
String resultPsd = "nines_mod.psd"; | |
String resultMod = "nines_mod.png"; | |
// Set the PNG options | |
PngOptions pngOpt = new PngOptions(); | |
pngOpt.setColorType(PngColorType.TruecolorWithAlpha); | |
// Set the PSD load options | |
PsdLoadOptions psdLoadOptions = new PsdLoadOptions(); | |
psdLoadOptions.setLoadEffectsResource(true); | |
// Load the PSD image | |
try (PsdImage image = (PsdImage) Image.load(source, psdLoadOptions)) { | |
// Save the original image as PNG | |
image.save(resultOrig, pngOpt); | |
// Test data for gradient | |
GradientColorPoint[] gradientColorPoints = new GradientColorPoint[]{ | |
new GradientColorPoint(Color.getRed(), 0, 50), | |
new GradientColorPoint(Color.getGreen(), 1024, 50), | |
new GradientColorPoint(Color.getBlue(), 2048, 50) | |
}; | |
GradientTransparencyPoint tp1 = new GradientTransparencyPoint(); | |
tp1.setLocation(0); | |
tp1.setMedianPointLocation(50); | |
tp1.setOpacity(128); | |
GradientTransparencyPoint tp2 = new GradientTransparencyPoint(); | |
tp2.setLocation(2048); | |
tp2.setMedianPointLocation(50); | |
tp2.setOpacity(176); | |
GradientTransparencyPoint[] gradientTransparencyPoints = new GradientTransparencyPoint[]{tp1, tp2}; | |
// Add stroke to layer 1 | |
StrokeEffect stroke = image.getLayers()[1].getBlendingOptions().addStroke(FillType.Gradient); | |
stroke.setSize(3); | |
GradientFillSettings gradientFillSettings = (GradientFillSettings) stroke.getFillSettings(); | |
gradientFillSettings.setColorPoints(gradientColorPoints); | |
gradientFillSettings.setTransparencyPoints(gradientTransparencyPoints); | |
// Add inner shadow to layer 2 | |
InnerShadowEffect innerShadow = image.getLayers()[2].getBlendingOptions().addInnerShadow(); | |
innerShadow.setAngle(60); | |
innerShadow.setColor(Color.getYellow()); | |
// Add drop shadow to layer 3 | |
DropShadowEffect dropShadow = image.getLayers()[3].getBlendingOptions().addDropShadow(); | |
dropShadow.setAngle(30); | |
dropShadow.setColor(Color.getViolet()); | |
// Add gradient overlay to layer 4 | |
GradientOverlayEffect gradientOverlay = image.getLayers()[4].getBlendingOptions().addGradientOverlay(); | |
gradientOverlay.getSettings().setColorPoints(gradientColorPoints); | |
gradientOverlay.getSettings().setTransparencyPoints(gradientTransparencyPoints); | |
// Add color overlay to layer 5 | |
ColorOverlayEffect colorOverlay = image.getLayers()[5].getBlendingOptions().addColorOverlay(); | |
colorOverlay.setColor(Color.getAzure()); | |
colorOverlay.setOpacity((byte) 120); | |
// Add pattern overlay to layer 6 | |
PatternOverlayEffect patternOverlay = image.getLayers()[6].getBlendingOptions().addPatternOverlay(); | |
int[] patternData = new int[]{ | |
Color.getRed().toArgb(), Color.getTransparent().toArgb(), | |
Color.getTransparent().toArgb(), Color.getRed().toArgb() | |
}; | |
patternOverlay.getSettings().setPatternData(patternData); | |
patternOverlay.getSettings().setPatternWidth(2); | |
patternOverlay.getSettings().setPatternHeight(2); | |
// Add outer glow to layer 7 | |
OuterGlowEffect outerGlow = image.getLayers()[7].getBlendingOptions().addOuterGlow(); | |
outerGlow.setSize(10); | |
ColorFillSettings colorFillSettings = new ColorFillSettings(); | |
colorFillSettings.setColor(Color.getCrimson()); | |
outerGlow.setFillColor(colorFillSettings); | |
// Save the modified image as PNG and PSD | |
image.save(resultMod, pngOpt); | |
image.save(resultPsd); | |
} | |
} |