Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake translucent text suitable for image watermarking in VB .NET
DescriptionThis example shows how to make translucent text suitable for image watermarking in VB .NET.
Keywordswatermark, image, translucent, transparent, opacity, VB.NET
CategoriesGraphics, VB.NET
 
To make translucent text, the program draws with two brushes. To make the brushes translucent, the program creates them using colors with alpha (opacity) values less than 255. The program draws the text using a translucent black brush and then draws it again shifted one pixel right and down with a translucent white brush. The final picture is slightly darkened along the upper and left edges of the text and lightened on the text's body.
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    Dim bm As Bitmap = picSrc.Image.Clone
    Dim gr As Graphics = Graphics.FromImage(bm)
    Dim brush1 As Brush
    Dim brush2 As Brush

    Dim string_format As New StringFormat
    string_format.Alignment = StringAlignment.Center

    Dim dy As Integer = gr.MeasureString("X", _
        Me.Font).Height * 1.2
    Dim x As Integer = bm.Width \ 2
    Dim y As Integer = 60

    For opacity As Integer = 31 To 255 Step 32
        brush1 = New SolidBrush(Color.FromArgb(opacity, 0, _
            0, 0))
        brush2 = New SolidBrush(Color.FromArgb(opacity, _
            255, 255, 255))
        Dim txt As String = "DRAWN WITH OPACITY " & _
            opacity.ToString
        gr.DrawString(txt, Me.Font, brush1, x, y, _
            string_format)
        gr.DrawString(txt, Me.Font, brush2, x + 1, y + 1, _
            string_format)
        y += dy
    Next opacity

    picResult.Image = bm
    gr.Dispose()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated