LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

LoadPsdChannel Method

Example 





A System.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 channel to load. This index is zero-based. Pass 0 to load the first channel, 1 to load the second channel, etc.
a CodecsPsdChannelInfo object to be updated with information about the loaded channel. Pass a null reference (Nothing in Visual Basic) for this parameter if channel information is not needed.
Loads the specified channel from the specified PSD file. .NET support
Syntax
'Declaration
 
Public Function LoadPsdChannel( _
   ByVal fileName As String, _
   ByVal bitsPerPixel As Integer, _
   ByVal order As CodecsLoadByteOrder, _
   ByVal channelIndex As Integer, _
   ByVal channelInfo As CodecsPsdChannelInfo _
) As RasterImage
'Usage
 
Dim instance As RasterCodecs
Dim fileName As String
Dim bitsPerPixel As Integer
Dim order As CodecsLoadByteOrder
Dim channelIndex As Integer
Dim channelInfo As CodecsPsdChannelInfo
Dim value As RasterImage
 
value = instance.LoadPsdChannel(fileName, bitsPerPixel, order, channelIndex, channelInfo)
 function Leadtools.Codecs.RasterCodecs.LoadPsdChannel( 
   fileName ,
   bitsPerPixel ,
   order ,
   channelIndex ,
   channelInfo 
)

Parameters

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

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.
order
The desired color order.
channelIndex
Index of the channel to load. This index is zero-based. Pass 0 to load the first channel, 1 to load the second channel, etc.
channelInfo
a CodecsPsdChannelInfo object to be updated with information about the loaded channel. Pass a null reference (Nothing in Visual Basic) for this parameter if channel information is not needed.

Return Value

The Leadtools.RasterImage object that this method loads.
Remarks

Use this method to load PSD files only.

This method works similarly to a normal Load(String) or LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) methods, except that it loads only a channel from a PSD file. It loads the channel specified in channelIndex.

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

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

Example
 
Public Sub LoadPsdChannels()
      Dim codecs As New RasterCodecs()

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Sunflower.psd")

      Dim imageInfo As CodecsImageInfo = codecs.GetInformation(srcFileName, False)
      For iCount As Integer = 0 To imageInfo.Psd.Channels - 1
         Dim ChannelInfo As New CodecsPsdChannelInfo()
         Dim ChannelImage As RasterImage = codecs.LoadPsdChannel(srcFileName, 0, CodecsLoadByteOrder.Rgb, iCount, ChannelInfo)

         Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Channel_")
         destFileName = destFileName & iCount & ".Bmp"

         codecs.Save(ChannelImage, destFileName, RasterImageFormat.Bmp, ChannelImage.BitsPerPixel)

         ChannelImage.Dispose()
      Next
      ' Clean up
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void LoadPsdChannels()
     {
         RasterCodecs codecs = new RasterCodecs();

         string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Sunflower.psd");

         CodecsImageInfo imageInfo = codecs.GetInformation(srcFileName, false);
         for (int iCount = 0; iCount < imageInfo.Psd.Channels; iCount++)
         {
             CodecsPsdChannelInfo ChannelInfo = new CodecsPsdChannelInfo();
             RasterImage ChannelImage = codecs.LoadPsdChannel(srcFileName, 0, CodecsLoadByteOrder.Rgb, iCount, ChannelInfo);

             string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Channel_");
             destFileName = destFileName + iCount + ".Bmp";

             codecs.Save(ChannelImage, destFileName, RasterImageFormat.Bmp, ChannelImage.BitsPerPixel);

             ChannelImage.Dispose();
         }
         // Clean up 
         codecs.Dispose();
     }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterCodecsExamples.prototype.LoadPsdChannels = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         var srcFileName = "Assets\\Sunflower.psd";
         var loadFile;
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFileX) {
            loadFile = loadFileX;
            return codecs.getInformationAsync(LeadStreamFactory.create(loadFile), false, 1)
         })
            .then(function (imageInfo) {
               for (var iCount = 0; iCount < imageInfo.psd.Channels; iCount++) {
                  var ChannelImage;
                  var ChannelInfo = new CodecsPsdChannelInfo();
                  var async = codecs.loadPsdChannelAsync(LeadStreamFactory.create(loadFile), 0, CodecsLoadByteOrder.rgb, iCount, ChannelInfo);
                  return WinJS.Promise.join(async).then(function (channelImage) {
                     ChannelImage = channelImage;
                     var destFileName = "Channel_";
                     destFileName = destFileName + iCount + ".Bmp";

                     return Tools.AppLocalFolder().createFileAsync(destFileName)
                  })
                  .then(function (saveFile) {
                     return codecs.saveAsync(ChannelImage, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, ChannelImage.BitsPerPixel)
                  })
                  .then(function () {

                     ChannelImage.close();
                  });
               }
            }).then(function () {
               // Clean up 
               codecs.close();
            });
      }
   }
}
[TestMethod]
public async Task LoadPsdChannels()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Sunflower.psd";

   IStorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   CodecsImageInfo imageInfo = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), false, 1);
   for (int iCount = 0; iCount < imageInfo.Psd.Channels; iCount++)
   {
      CodecsPsdChannelInfo ChannelInfo = new CodecsPsdChannelInfo();
      RasterImage ChannelImage = await codecs.LoadPsdChannelAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.Rgb, iCount, ChannelInfo);

      string destFileName = "Channel_";
      destFileName = destFileName + iCount + ".Bmp";

      IStorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);

      await codecs.SaveAsync(ChannelImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, ChannelImage.BitsPerPixel);

      ChannelImage.Dispose();
   }
   // Clean up 
   codecs.Dispose();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterCodecs Class
RasterCodecs Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.