You have learnt how to write a watermark text with different shape from the previous tutorial. You might be wondering, is there a way to customize a shape in CoolWatermark? The answer is YES! You just need to use the ShapeStyle.Customize and then specify the Shape structure Dest property, which defines a parallelogram to warp the text. A valid parallelogram must have exact 4 elements, which define the four corners of the text area (top-left, top-right, bottom-left, and bottom-right).
The Dest property is a PointF type array and it defines only the difference between the original text area and the destination text area. It might be easier if explain it through some photos.
For example, everytime when you write a watermark to an image, no matter it's a text or another image, it must be contained in an area, which usually is considered as a rectangle. The below image has a black border around the text, and the border describes the area that wraps the watermark.
You can read the container size by accessing CoolWatermark.BoundedArea after writing the watermark. The BoundedArea will only be correct the watermark is written, because the area is calculated during the wirting.
Normally, a rectangle has 4 points: top-left, top-right, bottom-left, and bottom-right. What you need to do is set difference for those 4 points in this property. Therefore, setting zero to all of them means no warp occurs. You can try this functionality in the DEMO application. When you select Customize ShapeStyle and click OK button, the following button will display.
The above setting means I want to move the top-right corner vertically -50 pixels (upwards) and bottom-right corner vertically 50 pixels (downwards). It will look like the built-in zoom in shape. In the next figure, I wrote a normal watermark text in black first, then write another text in yellow at the same place with a customized shape as above setting. The black border simply acts as a reference.
Next I will try a different setting as below:
It means I want to move the top-left corner horizontally 20 pixels (rightwards) and top-right corner horizontally -20 pixels (leftwards). It will look like the built-in zoom up shape.
Now I believe you have learnt how to customize a shape. By using different Dest value, you can have many interesting shapes. The following code will do a little twist to the top-left corner by setting X-Coordinate 50 and Y-Coordinate -50.
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: writer.PositionStyle = PositionStyle.MiddleCenter
5: writer.FontFamily = New FontFamily("Arial")
6: writer.FontSize = 48
7:
8: Dim shape As New IC.CoolWatermark.Shape()
9: shape.ShapeStyle = ShapeStyle.Customize
10:
11: Dim top_left_corner As New PointF(50, -50)
12: Dim others As New PointF(0, 0)
13: shape.Dest = New PointF() {top_left_corner, others, others, others}
14:
15: writer.Shape = shape
16:
17: image = writer.WriteText("Watermark")
18: 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: writer.PositionStyle = IC.CoolWatermark.PositionStyle.MiddleCenter;
6: writer.FontFamily = new FontFamily("Arial");
7: writer.FontSize = 48;
8:
9: IC.CoolWatermark.Shape shape = new IC.CoolWatermark.Shape();
10: shape.ShapeStyle = IC.CoolWatermark.ShapeStyle.Customize;
11:
12: PointF top_left_corner = new PointF(50.0f, -50.0f);
13: PointF others = new PointF(0, 0);
14: shape.Dest = new PointF[] { top_left_corner, others, others, others };
15:
16: writer.Shape = shape;
17:
18: image = writer.WriteText("Watermark");
19: writer.Dispose();
The code will generate a result similar to the following:
[Back to Top]