←Select platform

MaskImage Property

Summary
The transparency mask channel of the saved PSD layer.
Syntax
C#
Objective-C
C++/CLI
Python
public RasterImage MaskImage { get; set; } 
@property (nonatomic, strong, nullable) LTRasterImage *maskImage; 
public: 
property RasterImage^ MaskImage { 
   RasterImage^ get(); 
   void set (    RasterImage^ ); 
} 
MaskImage # get and set (CodecsPsdLayerInfo) 

Property Value

A RasterImage object that specifies the transparency mask channel of the saved PSD layer. The default value is null.

Remarks

This is an 8-bit grayscale image. The value of each pixel indicates the amount of transparency the data of the original image has at this point. For example, if the value is 0xFF at a certain point, the pixel value of the layer image at that point is not transparent at all. If the value was 0x00, the pixel value of the layer image at that point is fully transparent. If the value is between these two, it indicates the degree of transparency the pixel value of the layer image has at that point.

When loading, if you set the LoadMaskImage property to true, then this property will hold an RasterImage object that represents the transparency mask channel found in the PSD file.

If the mask image does not need to be loaded, pass false to LoadMaskImage. The value of MaskImage will not be used. Passing false to LoadMaskImage saves the transparency mask as full white image, which represents full visibility of the layer.

When saving, if this is a valid image, then it should be of the same width and height as the corresponding layer image. It should also be an 8-bit grayscale image.

For more information, refer to FILE FORMATS SPECIFICATION from Adobe.

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:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools.Codecs Assembly

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