GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureImaging Class / GetTextHeight Method
GdPicture image identifier.
Text to draw.
The name of the font. IE: "Arial".
The font size in units specified by the FontSetUnit() method.
A member of the FontStyle enumeration.
Example





In This Topic
GetTextHeight Method (GdPictureImaging)
In This Topic
Calculate the height of the specified text, based on the specified font, font size and font style. The result is measured in units specified by the FontSetUnit() method.
Syntax
'Declaration
 
Public Function GetTextHeight( _
   ByVal ImageID As Integer, _
   ByVal Text As String, _
   ByVal FontName As String, _
   ByVal FontSize As Single, _
   ByVal FontStyle As GdPictureFontStyle _
) As Single
public float GetTextHeight( 
   int ImageID,
   string Text,
   string FontName,
   float FontSize,
   GdPictureFontStyle FontStyle
)
public function GetTextHeight( 
    ImageID: Integer;
    Text: String;
    FontName: String;
    FontSize: Single;
    FontStyle: GdPictureFontStyle
): Single; 
public function GetTextHeight( 
   ImageID : int,
   Text : String,
   FontName : String,
   FontSize : float,
   FontStyle : GdPictureFontStyle
) : float;
public: float GetTextHeight( 
   int ImageID,
   string* Text,
   string* FontName,
   float FontSize,
   GdPictureFontStyle FontStyle
) 
public:
float GetTextHeight( 
   int ImageID,
   String^ Text,
   String^ FontName,
   float FontSize,
   GdPictureFontStyle FontStyle
) 

Parameters

ImageID
GdPicture image identifier.
Text
Text to draw.
FontName
The name of the font. IE: "Arial".
FontSize
The font size in units specified by the FontSetUnit() method.
FontStyle
A member of the FontStyle enumeration.

Return Value

The height of the text measured in units specified by the FontSetUnit() method.
Remarks

This method requires the Image Documents component to run.

Example
Drawing the red text and the black text border based on the text width and height on jpeg image.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
    int imageID = gdpictureImaging.CreateGdPictureImageFromFile("input.jpg");
    string text = "GdPicture.PDF";
    
    // Set font unit to Pixel
    gdpictureImaging.FontSetUnit(UnitMode.UnitPixel);
    
    float width = gdpictureImaging.GetTextWidth(imageID, text, "Arial", 24, GdPicture14.FontStyle.FontStyleRegular);
    float height = gdpictureImaging.GetTextHeight(imageID, text, "Arial", 24, GdPicture14.FontStyle.FontStyleRegular);
 
    // Draw the text.
    gdpictureImaging.DrawText(imageID, text, 10, 10, 24, GdPicture14.FontStyle.FontStyleRegular, Color.Red, "Arial", true);
 
    // Draw the border rectangle.
    gdpictureImaging.DrawRectangle(imageID, 10, 10, (int)width, (int)height, 1, Color.Black, true);
 
    gdpictureImaging.SaveAsJPEG(imageID, "output.jpg");
    gdpictureImaging.ReleaseGdPictureImage(imageID);
}
See Also