GdPicture.NET.14
GdPicture14 Namespace / GdPictureImaging Class / DrawTextBox Method / DrawTextBox(Int32,String,Int32,Int32,Int32,Int32,Single,TextAlignment,FontStyle,Int32,String,Boolean,Boolean) Method
GdPicture image identifier.
Text to draw.
Specifies the x-coordinate of the upper-left corner of the text box.
Specifies the y-coordinate of the upper-left corner of the text box.
Specifies the width, in pixels, of the text box.
Specifies the height, in pixels, of the text box.
The font size in units specified by the FontSetUnit() method.
A member of the TextAlign enumeration.
A member of the FontStyle enumeration.
Color of the text. A suitable color value can be obtained by using the ARGBI() method.
The name of the font. IE: "Arial".
Set this parameter to True to draw the textbox that bounds the text.
Set to True to apply the Antialiasing algorithm else False.
Example





In This Topic
DrawTextBox(Int32,String,Int32,Int32,Int32,Int32,Single,TextAlignment,FontStyle,Int32,String,Boolean,Boolean) Method
In This Topic
Draws an aligned text into a bounding box on a GdPicture image. The drawing color is specified with an integer value.
Syntax
'Declaration
 
Public Overloads Function DrawTextBox( _
   ByVal ImageID As Integer, _
   ByVal Text As String, _
   ByVal Left As Integer, _
   ByVal Top As Integer, _
   ByVal Width As Integer, _
   ByVal Height As Integer, _
   ByVal FontSize As Single, _
   ByVal Alignment As TextAlignment, _
   ByVal FontStyle As FontStyle, _
   ByVal TextColor As Integer, _
   ByVal FontName As String, _
   ByVal DrawBox As Boolean, _
   ByVal AntiAlias As Boolean _
) As GdPictureStatus
public GdPictureStatus DrawTextBox( 
   int ImageID,
   string Text,
   int Left,
   int Top,
   int Width,
   int Height,
   float FontSize,
   TextAlignment Alignment,
   FontStyle FontStyle,
   int TextColor,
   string FontName,
   bool DrawBox,
   bool AntiAlias
)
public function DrawTextBox( 
    ImageID: Integer;
    Text: String;
    Left: Integer;
    Top: Integer;
    Width: Integer;
    Height: Integer;
    FontSize: Single;
    Alignment: TextAlignment;
    FontStyle: FontStyle;
    TextColor: Integer;
    FontName: String;
    DrawBox: Boolean;
    AntiAlias: Boolean
): GdPictureStatus; 
public function DrawTextBox( 
   ImageID : int,
   Text : String,
   Left : int,
   Top : int,
   Width : int,
   Height : int,
   FontSize : float,
   Alignment : TextAlignment,
   FontStyle : FontStyle,
   TextColor : int,
   FontName : String,
   DrawBox : boolean,
   AntiAlias : boolean
) : GdPictureStatus;
public: GdPictureStatus DrawTextBox( 
   int ImageID,
   string* Text,
   int Left,
   int Top,
   int Width,
   int Height,
   float FontSize,
   TextAlignment Alignment,
   FontStyle FontStyle,
   int TextColor,
   string* FontName,
   bool DrawBox,
   bool AntiAlias
) 
public:
GdPictureStatus DrawTextBox( 
   int ImageID,
   String^ Text,
   int Left,
   int Top,
   int Width,
   int Height,
   float FontSize,
   TextAlignment Alignment,
   FontStyle FontStyle,
   int TextColor,
   String^ FontName,
   bool DrawBox,
   bool AntiAlias
) 

Parameters

ImageID
GdPicture image identifier.
Text
Text to draw.
Left
Specifies the x-coordinate of the upper-left corner of the text box.
Top
Specifies the y-coordinate of the upper-left corner of the text box.
Width
Specifies the width, in pixels, of the text box.
Height
Specifies the height, in pixels, of the text box.
FontSize
The font size in units specified by the FontSetUnit() method.
Alignment
A member of the TextAlign enumeration.
FontStyle
A member of the FontStyle enumeration.
TextColor
Color of the text. A suitable color value can be obtained by using the ARGBI() method.
FontName
The name of the font. IE: "Arial".
DrawBox
Set this parameter to True to draw the textbox that bounds the text.
AntiAlias
Set to True to apply the Antialiasing algorithm else False.

Return Value

A member of the GdPictureStatus enumeration.
Remarks
To draw watermark text use an ARGB value with alpha component < 255.

This method requires the Image Documents component to run.

Example
Drawing some text on images.
Drawing red text using left aligned text box on a jpeg image.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
    int imageID = gdpictureImaging.CreateGdPictureImageFromFile("input.jpg");
 
    // Draw text in the top left corner of the image.
    gdpictureImaging.DrawTextBox(imageID, "This is left aligned text by GdPicture.Net", 5, 5, 250, 150, 24, TextAlignment.TextAlignmentNear, GdPicture14.FontStyle.FontStyleRegular, gdpictureImaging.ARGBI(255, 255, 0, 0), "Arial", true, true);
    gdpictureImaging.SaveAsJPEG(imageID, "output.jpg");
    gdpictureImaging.ReleaseGdPictureImage(imageID);
}
Drawing sample text into a bounding box and saving the result into a png file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
    GdPicture14.FontStyle fontStyle = GdPicture14.FontStyle.FontStyleItalic;
    string text = "Long sample text";
    int redColor = gdpictureImaging.ARGBI(255, 255, 0, 0);
    int fontSize = 12;
 
    // Create background image.
    int backImage = gdpictureImaging.CreateNewGdPictureImage(320, 200, 32, gdpictureImaging.ARGBI(255, 255, 255, 255));
 
    // Draw sample text into the background image.
    gdpictureImaging.DrawTextBox(backImage, text, 20, 20, 100, 40, fontSize, TextAlignment.TextAlignmentNear, fontStyle, redColor, "Times", true, true);
    gdpictureImaging.SaveAsPNG(backImage, "output.png");
 
    // Release used resources.
    gdpictureImaging.ReleaseGdPictureImage(backImage);
}
See Also