Setting Digital Substitution in GDI+ using VB.NET

In this article I will explain about Setting Digital Substitution in GDI+.
  • 2130

The SetDigitSubstitution method can be used to substitute digits in a string on the basis of a user's local area. SetDigitSubstitution takes a parameter of the SetDigitSubstitution enumeration, the members of which are described in Table 5.12.

TABLE 5.12: StringDigitSubstitute members




Provides substitutions digits based on the national language of the user's locale.


Disables substitutions.


Provides substitution digits based on user's native script or language.


Provides a user-defined substitution.

Rendering Text with Quality and Performance

Here we will discuss the TextRenderingHint property of the Graphics class.

Note: The TextRenderingHint enumeration is defined in the System.Drawing.Text namespace.

The TextRenderingHint property of the Graphics class defines the quality of text rendered on graphics surfaces. The quality also affects drawing performance. For best performance, select low-quality rendering. Better quality will produce slower rendering. For LCD displays, ClearType text provides the best quality.

The TextRenderingHint property takes a value of type TextRenderingHint enumeration. The members of the TextRenderingHint enumeration are described in Table 5.13.

Listing 5.12 uses the TextRenderingHint property to draw text with different options. The code draws four different text strings using different text rendering hint options.

LISTING 5.12: Using TextRenderingHint to set the quality of text

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Text
Imports System.Linq
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Public Class Form1

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim g As Graphics = Me.CreateGraphics()
        Dim redBrush As New SolidBrush(Color.Red)
        Dim verdana16 As New Font("Verdana", 16)
        Dim text1 As String = "Text with SingleBitPerPixel"
        Dim text2 As String = "Text with ClearTypeGridFit"
        Dim text3 As String = "Text with AntiAliasing"
        Dim text4 As String = "Text with SystemDefault"

        'Set TextRenderingHint property of surface
        'to single bit per pixel
        g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel

        'Draw string
        g.DrawString(text1, verdana16, redBrush, New PointF(10, 10))

        'Set TextRenderingHint property of surface to ClearType grid fit
        g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit

        'Draw string
        g.DrawString(text2, verdana16, redBrush, New PointF(10, 60))

        'Set TextRenderingHint property to surface to Antialias
        g.TextRenderingHint = TextRenderingHint.AntiAlias

        'Draw string
        g.DrawString(text3, verdana16, redBrush, New PointF(10, 100))

        'Set TextRenderingHint property of surface to SystemDefault
        g.TextRenderingHint = TextRenderingHint.SystemDefault

        'Draw string
        g.DrawString(text4, verdana16, redBrush, New PointF(10, 150))

        'Dispose of objects
    End Sub
End Class

TABLE 5.12: TextRenderingHint members




Characters are rendered by anti-aliasing without hinting. AntiAlias offers good quality, but slow performance.


Characters are anti-aliased with hinting. AntiAliasGridFit offers good quality and high performance.


Characters are drawn by ClearType bitmap with hinting. This is the highest-quality settings, with slow performance. It takes advantage of ClearType font features, if available.


Characters are drawn with each glyph's bitmap. Hinting is not used.


Characters are drawn with each glyph's bitmap. Hinting is used to improve character appearance on stems and curvature.


Characters are drawn with each glyph's bitmap, with the system's default rendering hint.

Figure 5.17 shows the output from Listing 5.12. Different TextRenderingHint options result with higher or lower quality. (How clearly this shows up will vary on different displays-and it may be hard to see in print.)


FIGURE 5.17: Using different TextRenderingHint setting to draw text


Hope the article would have helped you in understanding Setting Digital Substitution in GDI+. Read other articles on GDI+ on the website.


More Articles

© 2020 DotNetHeaven. All rights reserved.