This sample shows how to use mask images.
You can add a transparent image to your PDF document using PdfDocument.AddImage method with a mask image as a parameter. Mask image must have the same width and height as an image to be made transparent and their pixel data must be encoded using 1 bit per pixel.
All pixels in the resulting image that correspond to the black pixels of a mask image will be drawn unchanged. All pixels in the resulting image that correspond to the white pixels of a mask image will not be drawn. Black pixels in a mask image are encoded using '0' bits. White pixels in a mask image are encoded using '1' bits.
using System.Diagnostics; using System.Drawing; namespace BitMiracle.Docotic.Pdf.Samples { public static class ImageMasks { public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. PdfDocument pdf = new PdfDocument(); PdfCanvas canvas = pdf.Pages[0].Canvas; canvas.Resolution = 150; canvas.Brush.Color = new PdfRgbColor(0, 255, 0); canvas.DrawRectangle(new RectangleF(50, 450, 1150, 150), PdfDrawMode.Fill); PdfImage image = pdf.AddImage("Sample data/pink.png", "Sample data/pinkMask.tif"); canvas.DrawImage(image, 550, 200); string pathToFile = "ImageMasks.pdf"; pdf.Save(pathToFile); pdf.Dispose(); Process.Start(pathToFile); } } }
Imports System.Diagnostics Imports System.Drawing Imports BitMiracle.Docotic.Pdf Namespace BitMiracle.Docotic.Pdf.Samples Public NotInheritable Class ImageMasks Public Shared Sub Main() ' NOTE: ' When used in trial mode, the library imposes some restrictions. ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx ' for more information. Dim pdf As New PdfDocument() Dim canvas As PdfCanvas = pdf.Pages(0).Canvas canvas.Resolution = 150 canvas.Brush.Color = New PdfRgbColor(0, 255, 0) canvas.DrawRectangle(New RectangleF(50, 450, 1150, 150), PdfDrawMode.Fill) Dim image As PdfImage = pdf.AddImage("Sample data/pink.png", "Sample data/pinkMask.tif") canvas.DrawImage(image, 550, 200) Dim pathToFile As String = "ImageMasks.pdf" pdf.Save(pathToFile) pdf.Dispose() Process.Start(pathToFile) End Sub End Class End Namespace
