''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' This sample demonstrates how to add a text watermark
'' to an image. The image is rendered using its native
'' resolution on a GcBitmap, then the watermark text
'' is drawn on top using a semitransparent color.
'' The resulting bitmap with the added watermark
'' can be saved to any of the supported image formats.
Public Class Watermark
Function GenerateImage(
ByVal pixelSize As Size,
ByVal dpi As Single,
ByVal opaque As Boolean,
Optional ByVal sampleParams As String() = Nothing) As GcBitmap
Dim Inch = dpi
Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
Using g = bmp.CreateGraphics(Color.White)
Using img = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "reds.jpg"))
Dim rc = New RectangleF(0, 0, img.Width, img.Height)
g.DrawImage(img, rc, Nothing, ImageAlign.Default)
g.DrawString(
"Watermark",
New TextFormat() With
{
.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "calibrib.ttf")),
.FontSize = Inch,
.ForeColor = Color.FromArgb(128, Color.Yellow)
},
rc, TextAlignment.Center, ParagraphAlignment.Center, False)
Util.AddNote(
"The image above has a watermark added to it using text drawn with a semitransparent color.",
g, New RectangleF(Inch / 2, img.Height + Inch / 4, pixelSize.Width - Inch, pixelSize.Height - img.Height - Inch / 4))
'' Draw border around the whole image
g.DrawRectangle(New RectangleF(0, 0, bmp.Width, bmp.Height), Color.DarkSlateBlue, 4)
End Using
End Using
'' Done
Return bmp
End Function
End Class