How to add new layer to psd file

Hello , I use the code " psdImage.getLayers()[10] " to get the layers

but can I get the details of this layer , like layer mask or clipping
and i dont kow how to use the setLayer method ,
if I want to insert a new layer (or new layer mask)to the PSD file , how can I do it.
thank you !

Hi Ives,

Thank you for your inquiry.

This is to update you can use the following code lines to get the clipping or mask layer information respectively.

psdImage.getLayers()[10].getClipping();
psdImage.getLayers()[10].getLayerMaskData();
Layer can be inserted in the following way:

Psdimage.setLayers(new Layer[0]);
Layer layer = new Layer();
layer.setTop(17);
layer.setLeft(13);
layer.setBottom(61);
layer.setRight(86);
// set other properties and settings accordingly
image.setLayers(new Layer[] { layer });

thank you for the response .

I use following code try to insert the new layer
but I got the error message (NullPointerException) when trying to save the psdImage
--------------------------------------------------------------
psdImage.setLayers(new Layer[0]);

Layer layer = new Layer();
layer.setTop(100);
layer.setLeft(200);
layer.setRight(300);
layer.setBottom(400);

((PsdImage) image).setLayers(new Layer[]{ layer });

psdImage.save(dataDir + “simplesimple.psd”);
--------------------------------------------------------------
Did I make mistake for the usage?
I also have other questions that is how to insert a mask layer
and how to get layer group.

Hi Ives,


Thank you for writing us back.

Please forward us a sample application and the sample PSD file that you are using at your end. We will test the scenario at our end and will update you about our findings.

hello ,here is the code i use

-----------------------------------------------------
public static void main(String[] args) throws Exception {
String dataDir = Utils.getDataDir(ExportPsdLayersToImages2.class);

Image image = Image.load(dataDir + “test.psd”);

PsdImage psdImage = (PsdImage) image;

psdImage.setLayers(new Layer[0]);

Layer layer = new Layer();
layer.setTop(17);
layer.setLeft(13);
layer.setBottom(61);
layer.setRight(86);

((PsdImage)image).setLayers(new Layer[] { layer });
psdImage.save(dataDir + “simplesimple.psd”);
}
-----------------------------------------------------
I tried other psd files and got the same result.
Please help me and teach me how to insert a mask layer
and how get layer group.

Hi Ives,

Thank you for sharing sample file.

This is to update you that we have investigated the issue at our end. Initial investigation shows that the issue persists. The issue has been logged into our system with ID IMAGING-35420. Our product team will further look into it. We will update you accordingly via this forum thread.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.