←Select platform

SavePsdWithLayers Method

Summary
Saves an image to a PSD file, along with the specified layers.
Syntax
C#
C++/CLI
Python
public void SavePsdWithLayers( 
   RasterImage image, 
   string fileName, 
   int bitsPerPixel, 
   RasterImage layerImages, 
   CodecsPsdLayerInfo[] layerInfos 
) 
def SavePsdWithLayers(self,image,fileName,bitsPerPixel,layerImages,] layerInfos): 

Parameters

image
The image to save.

fileName
The output file name.

bitsPerPixel
Resulting file's pixel depth. For color images this can be 24 or 32. For grayscale images this can be 8.

layerImages
An RasterImage object that contains layers (in each page) to save in the output file. The layers should have the same bits per pixel as the file. Every page in the image will be saved as a layer. The first page in the image will be interpreted as the first layer. The pages in the image must have the same bits per pixel as specified in  bitsPerPixel.

layerInfos
An optional array of CodecsPsdLayerInfo objects. If this is a null reference , then each layer will start at (0, 0) and will have the same size as the image. If this is not a null reference, then the layer information for each layer in  layerInfos will be stored here.The number of CodecsPsdLayerInfo objects must be the same as the number of pages in  layerImages.

Remarks

Use this method to save PSD files with layers.

Example
C#
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; 
      else 
         layersImage.AddPage(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); 
   image.Dispose(); 
   layersImage.Dispose(); 
 
   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 
      layerInfo.SetBlendModeKey(Encoding.ASCII.GetBytes(byteArray)); 
      Debug.WriteLine("Loaded layer at index {0} with updated Blend mode key:{1}", layer, Encoding.ASCII.GetString(layerInfo.GetBlendModeKey())); 
 
      layerImage.Dispose(); 
   } 
   else 
      Debug.WriteLine("No layers found in this PSD file"); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

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.