How do I set opacity on an image, so that it appers like a watermark?

Q: I'm trying to add a watermark image to a given page in my PDF
document. How do I set opacity on an image, so that it appers like a
watermark?

My code is as follows:

PDFNet.Initialize();
            PDFDoc doc = new PDFDoc(DIRtextBox.Text + "\\" +
"RBS_1.pdf");
            ElementBuilder bld = new ElementBuilder();
            ElementWriter writer = new ElementWriter();
            try
            {
                Page page = doc.GetPage(1);
                writer.Begin(page);
                string input_path = DIRtextBox.Text + "\\";

                Image img = Image.Create(doc, input_path +
"WaterMark.png");

                double pageWidth =
page.GetBox(Page.Box.e_media).Width();
                double imgHeight = img.GetImageHeight();

                double xPos = (pageWidth / 2) -
((img.GetImageWidth() / 4) / 2);
                double imgScaledHeight = img.GetImageHeight() / 4;
                double yPos = 0;
                double imgScaledWidth = img.GetImageWidth() / 4;

                Element element = bld.CreateImage(img, new
Matrix2D(imgScaledWidth, 0, 0, imgScaledHeight, xPos, yPos));
                writer.WritePlacedElement(element);

                writer.End();

                doc.Save(input_path + "addimage.pdf",
SDFDoc.SaveOptions.e_linearized);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "", MessageBoxButtons.OK);
            }
            finally
            {
                bld.Dispose();
                writer.Dispose();
                doc.Close();
            }
----------
A: There are several ways to apply transparency effect to an element
in PDF. For example, to set the constant opacity for the entire
element (i.e. image in your case), use
element.GetGState.SetFillOpacity(num). For example:

// In C# (VB.NET, Java, C++ is essentially the same).
// For relevant sample code please see to AddImage and ElementBuilder
samples.
Image image = Image.Create(doc, "my.jpg");
Element element = f.CreateImage(image, new
Matrix2D(image.GetImageWidth(), 0, 0, image.GetImageHeight(), 10,
10));
element.GetGState().SetFillOpacity(0.5); // opacity is a number is the
range [0..1]
// Optional: Alter the current blend mode...
// element.GetGState().SetBlendMode(...);
writer.WritePlacedElement(element);

It is also possible to apply a monochrome image mask or a grayscale
(i.e. soft) mask to an existing image using image.SetSoftMask(smask)
or image.SetImageMask(imask) methods. In this case the alpha channel
of the base image will correspond to the values from the mask image.

Another way to apply transparency effect to images or to any content
on the page is by setting the SoftMask property in the extended
graphics state (element.GetGState().SetSoftMask(msk)). This is the
most powerful way to control transparency in PDF, but is also the most
complicated to use.