imageComponent.NET - image processing .NET assemblies
Writing watermark text with drop-shadow effect

CoolWatermark supports drop-shadow effect by using a structure Shadow. So far it only supports watermark text not to image, but it will support drop-shadow to image in the future version. Using this structure is fairly easy, just intialize and enable it, assign to the watermark writer object, then perform the text writing. The following code will define a gray color shadow and (3, 3) offset, which means the shadwo offsets the original text 3 pixels both horizontally and vertically.

VB.NET

   1:  Dim bitmap As New System.Drawing.Bitmap(320, 240)
   2:  Dim image As System.Drawing.Image = bitmap
   3:  Dim writer As New IC.CoolWatermark.Writer(image)
   4:   
   5:  ' create a new shadow structure by using gray Color, and offset (3,3) 
   6:  Dim shadow As New IC.CoolWatermark.Shadow(Drawing.Color.Gray, 3, 3)
   7:  writer.Shadow = shadow
   8:   
   9:  ' use the pre-calcualted position
  10:  writer.PositionStyle = PositionStyle.MiddleCenter
  11:   
  12:  image = writer.WriteText("Hello Shadow")
  13:   
  14:  ' release resource
  15:  writer.Dispose()

C#

   1:  Bitmap bitmap = new Bitmap(320, 240);
   2:  System.Drawing.Image image = bitmap;
   3:   
   4:  IC.CoolWatermark.Writer writer = new IC.CoolWatermark.Writer(image);
   5:   
   6:  // create a new shadow structure by using gray Color, and offset (3,3) 
   7:  IC.CoolWatermark.Shadow shadow = new IC.CoolWatermark.Shadow(Color.Gray, 3, 3);
   8:  writer.Shadow = shadow;
   9:   
  10:  // use the pre-calcualted position
  11:  writer.PositionStyle = IC.CoolWatermark.PositionStyle.MiddleCenter;
  12:   
  13:  image = writer.WriteText("Hello Shadow");
  14:              
  15:  // release resource
  16:  writer.Dispose();

The result will be looked similar to the following figure:

A sample of shadow watermark text

Note

You might notice the current shadow implementation is simply writing a lighter color text behind with an offset. The result is OK but not the best. I am planning an improvement on it by adding a BlurRadius to the Shadow structure, which can have a blur effect, hence it will look much better.

A second improvement is, the current shadow effect can be only applied to text. The future version will definitely support shadow to overlapped image too.

[Back to Top]
Comments

If you feel this page can be improved or has any mistake, please enter your valuable opinion here. Or if you cannot find the information you are after, feel free to suggest a subject too. I appreciate any voice.

Your Name:
  
Your Email Address:
  
Comments: