Android Question Bitmap Creator draw text gradient

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi! I'm trying to study how works bitmap creator. Is possibile to draw a text with a gradient color and maybe a specific font?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you can draw it with Canvas then you can make a gradient out of it.

SS-2018-06-11_09.32.20.png


1. Create the mask bitmap with the text.
2. Create the gradient.
3. Call effects.DrawThroughMask. (https://www.b4x.com/android/forum/threads/b4x-bitmapcreator-effects.93608/#content)

B4X:
Sub Process_Globals
   Private effects As BitmapCreatorEffects
   Private xui As XUI
End Sub

Sub Globals

   Private ImageView1 As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
       effects.Initialize
   End If
   Activity.LoadLayout("1")
   Dim mask As Bitmap
   mask.InitializeMutable(ImageView1.Width, ImageView1.Height)
   Dim cvs As Canvas
   cvs.Initialize2(mask)
   cvs.DrawText("Hello World!!!", 5dip, 50dip, Typeface.DEFAULT_BOLD, 50, xui.Color_White, "LEFT")
   Dim gradient As BitmapCreator
   gradient.Initialize(ImageView1.Width / xui.Scale, ImageView1.Height / xui.Scale)
   gradient.FillGradient(Array As Int(xui.Color_Red, xui.Color_Green), gradient.TargetRect, "LEFT_RIGHT")
   Dim result As B4XBitmap = effects.DrawThroughMask(gradient.Bitmap, mask)
   ImageView1.SetBitmap(result)
End Sub
 
Upvote 0
Top