B4J Question How to Know the Paddings of the Text in a Snapshot of Text Node

xulihang

Active Member
Licensed User
Longtime User
B4X:
Dim tf As TextFlow
tf.Initialize
tf.AddText(textToDraw)
tf.SetFont(fx.DefaultFont(32))
Dim p As Pane = tf.CreateTextFlow
Dim img As Image = p.Snapshot2(fx.Colors.White)

I am trying to take snapshots of TextFlow to get the image of text. But it has paddings:

1759050327577.png



How do I know the values of the paddings so that I can crop the image to make the text take up the entire image?

Using B4XCanvas's measureText method seems a solution but I am not sure if it is the correct way.

B4X:
Dim cvs As B4XCanvas
cvs.Initialize(MainForm.RootPane)
Dim r As B4XRect = cvs.MeasureText(textToDraw,fx.DefaultFont(32))
Dim topPadding As Int = img.Height - r.Height
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0
Top