iOS Question FontToBitmap looks blurry

angel_

Well-Known Member
Licensed User
Longtime User
When I use FontToBitmap the text or icon looks blurry, in B4A it doesn't, there is a way to improve the sharpness and change the size (I see it a bit small)


IMG-0452.PNG
 

Attachments

  • B4iProject.zip
    255.7 KB · Views: 300

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Public Sub FontToBitmap (text As String, Fuente As B4XFont, color As Int) As B4XBitmap
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 32dip, 32dip)
    Dim cvs1 As B4XCanvas
    cvs1.Initialize(p)
    Dim fnt As B4XFont = Fuente
    Dim r As B4XRect = cvs1.MeasureText(text, fnt)
    Dim BaseLine As Int = cvs1.TargetRect.CenterY - r.Height / 2 - r.Top
    cvs1.DrawText(text, cvs1.TargetRect.CenterX, BaseLine, fnt, color, "CENTER")
    Dim bmp As B4XBitmap = cvs1.CreateBitmap
    Dim cg As NativeObject = bmp
    Dim uiimg As NativeObject
    bmp = uiimg.Initialize("UIImage").RunMethod("imageWithCGImage:scale:orientation:", Array(cg.RunMethod("CGImage", Null), 1, _
            cg.GetField("imageOrientation")))
    cvs1.Release
    Return bmp
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
or Test:

xui.CreateMaterialIcons(64)
xui.CreateFontAwesome(64)

SetFontToBitmap(Chr(0xF2B9), xui.CreateFontAwesome(64), 32, xui.Color_White)


B4X:
Public Sub SetFontToBitmap (FontText As String, FontType As B4XFont , FontSize As Float, FontColor As Int) As B4XBitmap
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 32dip, 32dip)
    Dim cvs1 As B4XCanvas
    cvs1.Initialize(p)
    Dim r As B4XRect = cvs1.MeasureText(FontText, xui.CreateFont2(FontType, FontSize))
    Dim BaseLine As Int = cvs1.TargetRect.CenterY - r.Height / 2 - r.Top
    cvs1.DrawText(FontText, cvs1.TargetRect.CenterX, BaseLine, xui.CreateFont2(FontType, FontSize), FontColor, "CENTER")
    cvs1.Invalidate
    Dim b As B4XBitmap = cvs1.CreateBitmap
    cvs1.Release
    Return b
End Sub
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
It still has that loss of sharpness that's kind of annoying that doesn't happen in B4A

IMG-0455.PNG
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
check this:


it can be a class problem (I have not used this class):

 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Use own symbols in
B4X:
TabControl.Pages = Array (CreateTabBarItem ("Chat",    0xF1D7, modulePage1), _
                              CreateTabBarItem ("Balance", 0xF24E, modulePage2), _
                              CreateTabBarItem ("Mail",    0xF003, modulePage3))
and compare results.

If in my sample a sharp is better, it's possible to think about modifications in SetFontToBitmap.
But I think the icons looks the same and a problem is in small size.
 
Upvote 0
Top