Leadtools.Codecs Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.17
LoadPsdLayer Method
See Also  Example
Leadtools.Codecs Namespace > RasterCodecs Class : LoadPsdLayer Method




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

Resulting image pixel depth. Valid values are:

ValueMeaning
0Keep the original file's pixel depth (Do not convert).
1 to 8The specified bits per pixel in the resulting image.
1212 bits per pixel in the resulting image.
1616 bits per pixel in the resulting image.
2424 bits per pixel in the resulting image.
3232 bits per pixel in the resulting image.
4848 bits per pixel in the resulting image.
6464 bits per pixel in the resulting image.

order
The desired color order.
layer
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.
layerInfo
a CodecsPsdLayerInfo object to be updated with information about the loaded layer. Pass a null reference (Nothing in Visual Basic) for this parameter if layer information is not needed.
Loads the specified layer from the specified PSD file.

Syntax

Visual Basic (Declaration) 
Public Function LoadPsdLayer( _
   ByVal fileName As String, _
   ByVal bitsPerPixel As Integer, _
   ByVal order As CodecsLoadByteOrder, _
   ByVal layer As Integer, _
   ByVal layerInfo As CodecsPsdLayerInfo _
) As RasterImage
Visual Basic (Usage)Copy Code
Dim instance As RasterCodecs
Dim fileName As String
Dim bitsPerPixel As Integer
Dim order As CodecsLoadByteOrder
Dim layer As Integer
Dim layerInfo As CodecsPsdLayerInfo
Dim value As RasterImage
 
value = instance.LoadPsdLayer(fileName, bitsPerPixel, order, layer, layerInfo)
C# 
public RasterImage LoadPsdLayer( 
   string fileName,
   int bitsPerPixel,
   CodecsLoadByteOrder order,
   int layer,
   CodecsPsdLayerInfo layerInfo
)
Managed Extensions for C++ 
public: RasterImage LoadPsdLayer( 
   string* fileName,
   int bitsPerPixel,
   CodecsLoadByteOrder order,
   int layer,
   CodecsPsdLayerInfo* layerInfo
) 
C++/CLI 
public:
RasterImage LoadPsdLayer( 
   String^ fileName,
   int bitsPerPixel,
   CodecsLoadByteOrder order,
   int layer,
   CodecsPsdLayerInfo^ layerInfo
) 

Parameters

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

Resulting image pixel depth. Valid values are:

ValueMeaning
0Keep the original file's pixel depth (Do not convert).
1 to 8The specified bits per pixel in the resulting image.
1212 bits per pixel in the resulting image.
1616 bits per pixel in the resulting image.
2424 bits per pixel in the resulting image.
3232 bits per pixel in the resulting image.
4848 bits per pixel in the resulting image.
6464 bits per pixel in the resulting image.

order
The desired color order.
layer
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.
layerInfo
a CodecsPsdLayerInfo object to be updated with information about the loaded layer. Pass a null reference (Nothing in Visual Basic) for this parameter if layer information is not needed.

Return Value

The RasterImage object that this method loads.

Example

Visual BasicCopy Code
RasterCodecs.LoadPsdLayer
      Public Sub PsdLayersExample()
         RasterCodecs.Startup()
         Dim codecs As RasterCodecs = New RasterCodecs()

         Dim layerFileNames As String() = _
         { _
            "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp", _
            "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample2.cmp", _
            "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample3.cmp" _
         }

         Dim srcFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"
         Dim destFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.psd"

         ' Load the layer images (as pages in 1 image)
         Dim layersImage As RasterImage = Nothing
         For Each layerFileName As String In layerFileNames
            Dim layerImage As RasterImage = codecs.Load(layerFileName)
            If layersImage Is Nothing Then
               layersImage = layerImage
            Else
               layersImage.AddPage(layerImage)
            End If
         Next layerFileName

         ' Load the image that is made up of all the layers
         Dim image As RasterImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.BgrOrGray, 1, 1)

         ' Save this image and all the layers
         codecs.SavePsdWithLayers(image, destFileName, 0, layersImage, Nothing)
         image.Dispose()
         layersImage.Dispose()

         Dim imageInfo As CodecsImageInfo = codecs.GetInformation(destFileName, False)
         If imageInfo.Psd.Layers > 0 Then
            Dim layer As Integer = 0
            Dim layerInfo As CodecsPsdLayerInfo = New CodecsPsdLayerInfo()
            Dim layerImage As RasterImage = codecs.LoadPsdLayer(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, layer, layerInfo)

            Dim blendModeKey As String = Encoding.ASCII.GetString(layerInfo.GetBlendModeKey())

            Console.WriteLine("Loaded layer at index {0}, size is {1} by {2}, Blend mode key:{3}", layer, layerImage.Width, layerImage.Height, blendModeKey)
            layerImage.Dispose()
         Else
            Console.WriteLine("No layers found in this PSD file")
         End If

         ' Clean up
         codecs.Dispose()
         RasterCodecs.Shutdown()
      End Sub
C#Copy Code
RasterCodecs.LoadPsdLayer 
      public void PsdLayersExample() 
      { 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
 
         string[] layerFileNames = 
         { 
            @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp", 
            @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample2.cmp", 
            @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample3.cmp", 
         }; 
 
         string srcFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"; 
         string destFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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); 
 
            string blendModeKey = Encoding.ASCII.GetString(layerInfo.GetBlendModeKey()); 
 
            Console.WriteLine("Loaded layer at index {0}, size is {1} by {2}, Blend mode key:{3}", layer, layerImage.Width, layerImage.Height, blendModeKey); 
            layerImage.Dispose(); 
         } 
         else 
            Console.WriteLine("No layers found in this PSD file"); 
 
         // Clean up 
         codecs.Dispose(); 
         RasterCodecs.Shutdown(); 
      }

Remarks

Use this method to load PSD files only.

This method works similarly to a normal Load method, 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.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also