Home... About... Arrange... FAQ... Customers...

Sample 19 - Get dimensions of a text string

The sample shows how to get the width and the height of a text string. It finds the smallest rectangle that the text string can be inscribed into.

GetTextTTFRectangle.vbs


Dim im1
Dim rect
'Create Object
Set im1 = CreateObject("ActiveImage.Images.1")


'Set path to true type fonts
im1.SetFontPathTTFAuto
'Set font size
im1.SetFontSizeTTF 36
'Set Font Name
im1.SetFontTTF "ariblk"


'Create empty canvass
im1.CreateImage 400, 200


im1.SetAlphaColor 0,0,0,0
im1.Fill 1,1

'Set Color
im1.SetAlphaColor 128, 0, 192,0

'Get rectangle 
rect = im1.GetTextTTFRectangle(50, 80 , "TONEC.COM")

'Draw a text with selected font
im1.DrawTextTTF  50, 80 , "TONEC.COM"

im1.SetAlphaColor 255, 0, 0,0
im1.DrawRectangle rect(0)-1,rect(1)-1,rect(2),rect(3)


'Save image to a file
im1.WriteToFile "C:\AI\GetTTFRect.png"
im1.SetImageType 4
im1.WriteToFile "C:\AI\GetTTFRect.bmp"
im1.SetImageType 1
im1.WriteToFile "C:\AI\GetTTFRect.jpg"
im1.SetImageType 3
im1.ConvertToPaletteNoAlpha
im1.WriteToFile "C:\AI\GetTTFRect.gif"

Set im1 = Nothing


Picture 1. GetTTFRect.gif (size - 10,5 Kb)


If you have any questions or bug reports, write to active.image@tonec.com for technical support.


© 2000-2001 All Rights Reserved

Tonec Inc., 16835 Algonquin Street #400, Huntington Beach, CA, 92649, fax: (509) 752-1450, e-mail: info@tonec.com