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

Discussion in 'Android Questions' started by MarkusR, Jun 4, 2018.

Similar threads

B4A Question Catch the bouncing smiley
B4A Tutorial Signature Capture Tutorial
B4A Tutorial SQL tutorial
B4A Question Add thumbnail with WriteToStream method
B4A Tutorial ListView tutorial
  1. MarkusR

    MarkusR Well-Known Member Licensed User

    i have a sub that make a texture but the text width looks different if me compare a tablet with a phone.
    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?

    Dim bmp As Bitmap
            bmp = TextToBitmap2(Description,
    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
    0%x0%y, Width, Height)

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

    Last edited: Jun 4, 2018
  2. DonManfred

    DonManfred Expert Licensed User

    why you are not using DP?
    MarkusR likes this.
  3. MarkusR

    MarkusR Well-Known Member Licensed User

    DP = dip?
    i used power of 2 texture size, i fear out of memory if me scale the texture size up.
  4. DonManfred

    DonManfred Expert Licensed User

    you are not using dip here. Don´t know if it makes a difference.
    MarkusR likes this.
  5. MarkusR

    MarkusR Well-Known Member Licensed User

  6. klaus

    klaus Expert Licensed User

    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)
    MarkusR likes this.
  7. MarkusR

    MarkusR Well-Known Member Licensed User

    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice