XImage SetMask Function. Assign a soft mask to the image. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

Assign a soft mask to the image.

 

   
Syntax  

[C#]
void SetMask(XImage mask, bool invert)

[Visual Basic]
Sub SetMask(mask As XImage, invert As Boolean)

Throws Exceptions may throw Exception()

 

   

Params
 
Name Description
mask The image containing the soft mask.
invert Whether to invert the mask.

 

   

Notes
 

Assign a soft mask or alpha channel. Soft masks are used to assign levels of transparency to an image.

The mask provided will be converted to a grayscale intensity map and may be scaled to ensure that the dimensions of the mask match those of the image. The assigned mask applies to all frames of the current image.

If the Invert parameter is set then the mask will be inverted - making transparent areas opaque and opaque areas transparent.

Different images within the mask can be accessed using the Frame property. Different portions of the mask can be selected using the Selection property.

Note that transparency is only applied to an Image if the Indirect property is true (which is generally the case).

 

   

Example
 

Here we read a TIFF file and present the data to the Image object. We then read a mask image and assign that to our Image. Finally we add the image to our document and then save the PDF.

[C#]
Doc theDoc = new Doc();
XImage theImg = new XImage();
XImage theMsk = new XImage();
theImg.SetFile(Server.MapPath("../mypics/mypic.tif"));
theMsk.SetFile(Server.MapPath("../mypics/mymask.jpg"));
theImg.SetMask(theMsk, true);
theMsk.Clear();
theDoc.Color.String = "0 0 0";
theDoc.FillRect();
theDoc.Rect.Inset(20, 20);
theDoc.AddImageObject(theImg, true);
theImg.Clear();
theDoc.Save(Server.MapPath("imagesetmask.pdf"));
theDoc.Clear();

[Visual Basic]
Dim theDoc As Doc = New Doc()
Dim theImg As XImage = New XImage()
Dim theMsk As XImage = New XImage()
theImg.SetFile(Server.MapPath("../mypics/mypic.tif"))
theMsk.SetFile(Server.MapPath("../mypics/mymask.jpg"))
theImg.SetMask(theMsk, True)
theMsk.Clear()
theDoc.Color.String = "0 0 0"
theDoc.FillRect()
theDoc.Rect.Inset(20, 20)
theDoc.AddImageObject(theImg, True)
theImg.Clear()
theDoc.Save(Server.MapPath("imagesetmask.pdf"))
theDoc.Clear()

Given the following input images.


mypic.tif

mymask.jpg

This is the kind of output you might expect.


imagesetmask.pdf