Merging Images and Watermarking in Visual Basic for .NET using csXImage.ocx

Two of the methods for merging images with csXImage are MergeFile and MergeBinary. These methods each provide the same functionality, enabling a second image to be merged into the image currently loaded in the control. With MergeBinary, the second image is read from a byte array variable. MergeFile, which is demonstrated in the demo VB.NET application, reads the second image from a file on disk.

Several options are available to the user to modify the way that the merge is carried out. These options are best demonstrated by showing the different effects achieved when a simple monochrome image, containing black text on a white background, is merged into a full colour photograph.

The two images being used for this demonstration are shown below. All the following examples were prepared using the VB.NET demo application, with the photograph on the left as the main image (loaded into the csXImage control before using the MergeFile method) and the text image on the right as the second image.

ActiveX load background image

Main image

ActiveX load foreground image

Second (merged) image

First let's look at the effect of allowing transparency in the second image. If a straightforward merge is carried out, with no transparency, the second image will be stamped onto the first image, hiding all the pixels of the first image covered by the rectangle of the second image. This is shown on the left below. If transparency is allowed in the second image, and the transparent colour is specified as white, then only the black text will be merged, with the remaining pixels of the original image retained. This is shown on the right. The equivalent VB code to give these effects is shown beside each image.

VB image without transparency

With AxImageBox1
  .MergeStyle =
    csXImageTrial.TxWMStyle.wmCentre
  .MergeTransparent = FALSE
  .MergeFile(MergeFileName)
End With

ActiveX image with white transparent

With AxImageBox1
  .MergeStyle =
    csXImageTrial.TxWMStyle.wmCentre
  .MergeTransparent = TRUE
  .MergeTransparentColor =
    System.Drawing.Color.White
  .MergeTransparency = 0
  .MergeFile(MergeFileName)
End With

In the above examples, the first image has been simply stamped onto the main image. Alternatively, it can be made more transparent by setting a value for the MergeTransparency property (0 to 100%). This can give a "watermark" effect. In the images below, a value of 80% has been used so the second image appears lightly blended into the main image.

Four examples are given, showing the four different values for the MergeStyle property. This property determines how the second image is positioned on the main image.

Merge image using ActiveX control

With AxImageBox1
  .MergeStyle =
    csXImageTrial.TxWMStyle.wmSingle
  .MergeTransparent = TRUE
  .MergeTransparentColor =
    System.Drawing.Color.White
  .MergeTransparency = 80
  .MergeFile(MergeFileName)
End With

ActiveX tiled watermark image

With AxImageBox1
  .MergeStyle =
    csXImageTrial.TxWMStyle.wmTile
  .MergeTransparent = TRUE
  .MergeTransparentColor =
    System.Drawing.Color.White
  .MergeTransparency = 80
  .MergeFile(MergeFileName)
End With

VB image watermark positioned centrally

With AxImageBox1
  .MergeStyle =
    csXImageTrial.TxWMStyle.wmCentre
  .MergeTransparent = TRUE
  .MergeTransparentColor =
    System.Drawing.Color.White
  .MergeTransparency = 80
  .MergeFile(MergeFileName)
End With

VB image repeating watermark

With AxImageBox1
  .MergeStyle =
    csXImageTrial.TxWMStyle.wmWrap
  .MergeTransparent = TRUE
  .MergeTransparentColor =
    System.Drawing.Color.White
  .MergeTransparency = 80
  .MergeFile(MergeFileName)
End With

In some cases, the image already loaded into the csXImage control is the one that needs to be used as the second image, with the main image being available on disk. Another property, MergeReverse, can be used to specify that the images will be merged in the opposite order.

The image resulting from a merge operation always retains the colour format and dimensions of the main image.

<<Previous page  Next page>>

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.