←Select platform

LoadPsdLayer Method

Loads the specified layer from the specified PSD file.
def LoadPsdLayer(self,fileName,bitsPerPixel,order,layer,layerInfo): 


A String containing the name of the image file to load.

Resulting image pixel depth. Valid values are:

Value Meaning
0 Keep the original file's pixel depth (Do not convert).
1 to 8 The specified bits per pixel in the resulting image.
12 12 bits per pixel in the resulting image.
16 16 bits per pixel in the resulting image.
24 24 bits per pixel in the resulting image.
32 32 bits per pixel in the resulting image.
48 48 bits per pixel in the resulting image.
64 64 bits per pixel in the resulting image.

The desired color order.

Index of the layer to load. This index is zero-based. Pass 0 to load the first layer, 1 to load the second layer, etc.

a CodecsPsdLayerInfo object to be updated with information about the loaded layer. Pass a null reference for this parameter if layer information is not needed.

Return Value

The RasterImage object that this method loads.


Use this method to load PSD files only.

This method works similarly to a normal Load or LoadAsync methods, except that it loads only a layer from a PSD file. It loads the layer specified in  layer.

Before calling this method, you may need to get or set file information, such as the number of layers on the file. Refer to CodecsPsdImageInfo.

The number of layers in a file is indicated in CodecsPsdImageInfo.Layers. If this number is 0, the file does not contains any layers and this method should not be called.


This example will create and save a PSD with layers before re-loading the first layer back

using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
public void PsdLayersExample() 
   RasterCodecs codecs = new RasterCodecs(); 
   string[] layerFileNames = 
   Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp"), 
   Path.Combine(LEAD_VARS.ImagesDir, "Sample2.cmp"), 
   Path.Combine(LEAD_VARS.ImagesDir, "Sample3.cmp"), 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.psd"); 
   // Load the layer images (as pages in 1 image) 
   RasterImage layersImage = null; 
   foreach (string layerFileName in layerFileNames) 
      RasterImage layerImage = codecs.Load(layerFileName); 
      if (layersImage == null) 
         layersImage = layerImage; 
   // Load the image that is made up of all the layers 
   RasterImage image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.BgrOrGray, 1, 1); 
   // Save this image and all the layers 
   codecs.SavePsdWithLayers(image, destFileName, 0, layersImage, null); 
   CodecsImageInfo imageInfo = codecs.GetInformation(destFileName, false); 
   if (imageInfo.Psd.Layers > 0) 
      int layer = 0; 
      CodecsPsdLayerInfo layerInfo = new CodecsPsdLayerInfo(); 
      RasterImage layerImage = codecs.LoadPsdLayer(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, layer, layerInfo); 
      layerInfo.Clipping = 0; 
      layerInfo.Left = 0; 
      layerInfo.LoadMaskImage = true; 
      layerInfo.MaskImage = null; 
      layerInfo.Name = null; 
      layerInfo.Opacity = 0; 
      layerInfo.Top = 0; 
      string blendModeKey = Encoding.ASCII.GetString(layerInfo.GetBlendModeKey()); 
      Debug.WriteLine("Loaded layer at index {0}, size is {1} by {2}, Blend mode key:{3}", layer, layerImage.Width, layerImage.Height, blendModeKey); 
      Debug.WriteLine("TransparencyProtected is {0}, Visible is {1}, Obsolete is {2} and Psd5OrLater is {3}", 
         layerInfo.TransparencyProtected, layerInfo.Visible, layerInfo.Obsolete, layerInfo.Psd5OrLater); 
      char[] byteArray = "dark".ToCharArray(); //Define Blend Mode Key 
      Debug.WriteLine("Loaded layer at index {0} with updated Blend mode key:{1}", layer, Encoding.ASCII.GetString(layerInfo.GetBlendModeKey())); 
      Debug.WriteLine("No layers found in this PSD file"); 
   // Clean up 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.