GetTextHeight Method (GdPictureImaging)
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.
public float GetTextHeight(
int ,
string ,
string ,
float ,
FontStyle
)
public function GetTextHeight(
: Integer;
: String;
: String;
: Single;
: FontStyle
): Single;
public function GetTextHeight(
: int,
: String,
: String,
: float,
: FontStyle
) : float;
public: float GetTextHeight(
int ,
string* ,
string* ,
float ,
FontStyle
)
public:
float GetTextHeight(
int ,
String^ ,
String^ ,
float ,
FontStyle
)
'Declaration
Public Function GetTextHeight( _
ByVal As Integer, _
ByVal As String, _
ByVal As String, _
ByVal As Single, _
ByVal As FontStyle _
) As Single
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.
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);
}