Android Question About FontAwesome and Material Icons

hanyelmehy

Active Member
Licensed User
Longtime User
When using
B4X:
Sub TextToBitmap (s As String, FontSize As Float) As Bitmap
   Dim bmp As Bitmap
   bmp.InitializeMutable(32dip, 32dip)
   Dim cvs As Canvas
   cvs.Initialize2(bmp)
   Dim h As Double = cvs.MeasureStringHeight(s, lblfontAwesome.Typeface, FontSize)
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, lblfontAwesome.Typeface, FontSize, Colors.White, "CENTER")
   Return bmp
End Sub
some icons not shown correctly (check image attached white arrow not shown in converted bitmap)
also its happens when using (Colors.Black) or other color
 

Attachments

  • s1.jpg
    2.5 KB · Views: 335

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
I tried. I can't get a good solution. Maybe one expert do it.

Only that:

B4X:
bmp.InitializeMutable(48dip, 48dip)

Dont know if it go help you.

We soon have CSbuilder.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I tested it with this code and I do see the arrow:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.SetBackgroundImage(TextToBitmap(Chr(0xF0EE), 30))
End Sub

Sub TextToBitmap (s As String, FontSize As Float) As Bitmap
   Dim bmp As Bitmap
   bmp.InitializeMutable(32dip, 32dip)
   Dim cvs As Canvas
   cvs.Initialize2(bmp)
   Dim h As Double = cvs.MeasureStringHeight(s, Typeface.FONTAWESOME, FontSize)
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.FONTAWESOME, FontSize, Colors.White, "CENTER")
   Return bmp
End Sub
 
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
i use v 6.3 it did not have Typeface.FONTAWESOME
 
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
its solved ,the problem is that i was load icons codes from older version than ttf font file
Thanks for all help
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
I am trying to substitute MSIconicDrawable with the B4A inbuilt support for FontAwsome.
How do I change the color of the Icon/Bitmap created using the Sub TextToBitmap ?. I am trying to place the Icon/Bitmap created using the Sub TextToBitmap() on the DSNavigationDrawer. DSNavigationDrawer expects either a Bitmap or BitmapDrawable to display the Icon on the Drawer.

In the following code, I tried replacing different colors, unfortunately, there seems no difference. Whatever color I use the Bitmap appears in Black color only cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.FONTAWESOME, FontSize, Colors.White, "CENTER")
The code doesn't have any effect on the color of the Bitmap/icon.
B4X:
'When using MSIconicDrawable, here I have the option to change the color of the icon
Dim IconHome As MSIconicDrawable  : IconHome.Initialize("gmd_home")  : IconHome.Color = 0xffff4081

'In this case how do I change the color of the icon ? ie TextToBitmap(Chr(0xF0EE), 30)
Dim oBitMap As BitmapDrawable
oBitMap.Initialize(TextToBitmap(Chr(0xF0EE), 30))

NavDrawer.NavigationView.Menu.AddWithGroup2(1, 1, 1, "Home", oBitMap  ).Checked = True
NavDrawer.NavigationView.Menu.AddWithGroup(1, 2, 2, "My Menu", TextToBitmap(Chr(0xF209), 30)  ).Checked = True

Sub TextToBitmap (s As String, FontSize As Float) As Bitmap
   Dim bmp As Bitmap
   bmp.InitializeMutable(32dip, 32dip)
   Dim cvs As Canvas
   cvs.Initialize2(bmp)
   Dim h As Double = cvs.MeasureStringHeight(s, Typeface.FONTAWESOME, FontSize)
   'Tried changing the color in the next line, but no effect on the final image. It is appearing as grey only
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.FONTAWESOME, FontSize, Colors.White, "CENTER")
   Return bmp
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…