Android Question [solved] different font width at different devices^^

MarkusR

Well-Known Member
Licensed User
Longtime User
i have a sub that make a texture but the text width looks different if me compare a tablet with a phone.
why?
my goal is to have the same texture at all devices.
currently one device looks good and at the other the text is cut.
is there a way to use a static font in asset folder or something else?
or did i made a mistake?

Code: Copy
Dim bmp As Bitmap
        bmp = TextToBitmap2(Description,13.0,Colors.White,256,256)

Code: Copy
Public Sub TextToBitmap2(Texts As List,TextSize As Float, Color As Int, Width As Int,Height As Int) As Bitmap

    Private Bitmap1 As Bitmap
    Private Canvas1 As Canvas
 
    Dim DestRect As Rect
    DestRect.Initialize(0%x, 0%y, Width, Height)

    Bitmap1.InitializeMutable( Width,Height)
    Canvas1.Initialize2(Bitmap1)
    Canvas1.AntiAlias = True
    Canvas1.DrawColor(Color)
    Dim y As Float
    y = 3%y + TextSize
    For Each T As String In Texts
        Canvas1.DrawText(T,1%x,y,Typeface.DEFAULT,TextSize, Colors.Black ,"LEFT")
        y = y + TextSize + 5dip
      Next
 
    Return Canvas1.Bitmap
 
End Sub

tablet
Screenshot_20180604-184252.png

phone
Screenshot_2018-06-04-18-43-03.png
 
Last edited:
DP = dip?
i used power of 2 texture size, i fear out of memory if me scale the texture size up.
 
Upvote 0
For me, another problem is here:
y = 3%y + TextSize
You are using TextSize as if it were pixels.
TextSize is density independant.
Try this code:
y = 3%y + Canvas1.MeasureStringHeight("Mg", Typeface.DEFAULT, TextSize)
 
Upvote 0
this Canvas1.MeasureString.. was very useful for width and height.
because texture memory i end up in resizing the font until one of the texts fit best in texture width.
its not a good solution to use a texture with texts, its better using a plane each char and make a 3d text of it.
 
Upvote 0
Back
Top