Canvas.
MeasureStringHeight (Text As String, Typeface As android.graphics.Typeface, TextSize As Float) As Float
Returns the height of the given text.
Example of drawing a blue text with white rectangle as the background:
Dim Rect1 As Rect
Dim width, height As Float
Dim t As String
t = "Text to write"
width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)
height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14)
Rect1.Initialize(100dip, 100dip, 100dip + width, 100dip + height)
Canvas1.DrawRect(Rect1, Colors.White, True, 0)
Canvas1.DrawText(t, Rect1.Left, Rect1.Bottom, Typeface.DEFAULT, 14, Colors.Blue, "LEFT")
Wish PdfDocument - Allow Canvas Measuring without StartPage - Robert Valentino    
Feb 27, 2019
Private mPDF As PdfDocument
mPDF.Initialize
mPDF.StartPage(mPageSize.Width, mPageSize.Height)
TextHeight = mPDF.Canvas.MeasureStringHeight(mMeasureHeightString, mFont_Roboto_Regular, (10 / mScale))
SubHeadingHeight = mPDF.Canvas.MeasureStringHeight(mMeasureHeightString... you can MeasureStringHeight or MeasureStringWidth
Normally I measure my Header items to determine where I want to...
B4A Question Max Text Size - RandomCoder    
May 26, 2015 it works correctly but if smaller then the textsize is too large even though the canvas MeasureStringHeight suggests that it should fit?
I've thrown together a small sample (attached), and the code...)
' Set canvas and initialise text size to try
Dim c As Canvas
c.Initialize(v)
Dim...)
Dim fltH As Float = c.MeasureStringHeight(str, Typeface.DEFAULT_BOLD, fltSize)
' Check...
link: is sized incorrectly because Canvas.MeasureStringHeight is incorrectly reporting the expected height...
B4A Question Question about text size - klaus (first post)    
Nov 7, 2015Canvas.MeasureStringHeight(Text As String, Typeface As Typeface, TextSize As Float)
Returns : Float...
link: you , I set the textSize on my device ; with Canvas.MeasureStringHeight I measure the real Height and...
B4A Question Canvas Draw Text Center Is Not Centering - Jeffrey Cameron (first post)    
Jun 22, 2018   
(2 reactions) add 1/2 of the text height to your Y value (see Canvas.MeasureStringHeight)....
link: )
End Sub
Sub CreateBitmap As Canvas
Dim bmp As Bitmap
bmp.InitializeMutable(200dip, 200dip...
B4A Question Canvas.DrawText Positioning issue/formula - RandomCoder (first post)    
Jun 22, 2015I'm pretty sure that the problem will be with the Canvas.MeasureStringHeight it is not reliable. Erel advised me in a previous post somewhere on the Forum to use StringUtils instead....
B4A Question DB to text for pdfcreate - harinder (first post)    
Dec 29, 2020)
yoff = yoff + pdf.Canvas.MeasureStringHeight(outputstr, Typeface.DEFAULT_BOLD, 30...("green")} ${rs.getstring("blue")}"$
pdf.Canvas.DrawText(outputstr, 250, 150...
link: )
yoff = yoff + pdf.Canvas.MeasureStringHeight(outputstr, Typeface.DEFAULT_BOLD, 30...
B4A Question Resize Label text with Java Object - klaus (first post)    
May 21, 2015   
(1 reaction)Unfortunately your code will not work in all cases because Canvas1.MeasureStringHeight returns different values depending on the text.
Example:
Canvas1.MeasureStringHeight("a", Typeface.DEFAULT, 16)
Canvas1.MeasureStringHeight("A", Typeface.DEFAULT, 16)
Canvas1.MeasureStringHeight("Aj", Typeface.DEFAULT, 16)
These three statements return different values !
The factor...
link: stringutils I have used Canvas.MeasureStringHeight, found I needed to use a 0.7 factor to get...
B4A Question fontsize multiple layout - Erel (first post)    
May 28, 2015   
(1 reaction)Canvas.MeasureStringHeight is based on a lower level API that doesn't behave in the same way that a Label or EditText will behave. StringUtils uses the same measurement process as the views....
link: Canvas.MeasureStringHeight is based on a lower level API that doesn't behave in the same way...
link: .MeasureStringWidth work to produce the correct size of text but Canvas.MeasureStringHeight does not...
B4A Question Listview label height - LucaMs (first post)    
Mar 31, 2014damn... and canvas MeasureStringHeight also don't calculates the text height as i need.
Thanks for you help....
link: .Initialize(lbl)
Dim CanvasStringHeight As Float
CanvasStringHeight = cnv.MeasureStringHeight(Note, lbl...
B4A Code Snippet [B4X] [XUI] Accurate Text Measurement and Drawing - Erel (first post)    
May 10, 2018   
(2 reactions)Since two years I'm good with using the known methods.
Note that it is not possible to accurately draw a border around text, like done in this example, with the standard Canvas.MeasureStringHeight method as it only returns the total height and lacks the height above baseline.
What makes wonder... B4J and B4i you can call this method without initializing the B4XCanvas object as the internal canvas... canvas and use it for all measurements....
Page: 1  
2  
3  
4  
5  
6  
7