Merging Images and Watermarking in Visual Basic using csXImage.ocx

Two of the methods for merging images with csXImage are MergeFile & 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 variant array. MergeFile, which is demonstrated in the demo VB 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 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 ImageBox1
  .MergeStyle = wmCentre
  .MergeTransparent = FALSE
  .MergeFile MergeFileName
End With

ActiveX image with white transparent

With ImageBox1
  .MergeStyle = wmCentre
  .MergeTransparent = TRUE
  .MergeTransparentColor = vbWhite
  .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 ImageBox1
  .MergeStyle = wmSingle
  .MergeTransparent = TRUE
  .MergeTransparentColor = vbWhite
  .MergeTransparency = 80
  .MergeFile MergeFileName
End With

ActiveX tiled watermark image

With ImageBox1
  .MergeStyle = wmTile
  .MergeTransparent = TRUE
  .MergeTransparentColor = vbWhite
  .MergeTransparency = 80
  .MergeFile MergeFileName
End With

VB image watermark positioned centrally

With ImageBox1
  .MergeStyle = wmCentre
  .MergeTransparent = TRUE
  .MergeTransparentColor = vbWhite
  .MergeTransparency = 80
  .MergeFile MergeFileName
End With

VB image repeating watermark

With ImageBox1
  .MergeStyle = wmWrap
  .MergeTransparent = TRUE
  .MergeTransparentColor = vbWhite
  .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.