I'm at a loss here. I need to dynamically draw text with Canvas.DrawText, and while it works the first time around, when the text is changed it overlaps.
I've tried:
Are you calling cnv.ClearRect(...) each time before the DrawText ?
eg
B4X:
Sub DrawIt(s As String)
cnv.ClearRect(0,0,cnv.Width ,cnv.Height)
cnv.DrawText(s,cnv.width/2,cnv.height, fx.DefaultFont(20),fx.Colors.Blue,"CENTER")
End Sub
Are you calling cnv.ClearRect(...) each time before the DrawText ?
eg
B4X:
Sub DrawIt(s As String)
cnv.ClearRect(0,0,cnv.Width ,cnv.Height)
cnv.DrawText(s,cnv.width/2,cnv.height, fx.DefaultFont(20),fx.Colors.Blue,"CENTER")
End Sub
Oh the ClearRect() does work, turns out I didn't do 0,0 for coordinates. However new problem. I need to be able to physically stretch this text sideways (as in make it really wide, not scaling font size)
Does BCTextEngine support this?
Previously, I've been able to achieve the stretch effect with B4A Canvas, I don't know why, but setting long widths and short heights in B4A allows the canvas to fully stretch the text to the view. B4J keeps the font size the same, and does not stretch to any bounds but tries to keep the text size the same throughout it seems.
I'm at a loss here. I need to dynamically draw text with Canvas.DrawText, and while it works the first time around, when the text is changed it overlaps.
I've tried:
Fx.Colors.Transparent doesn't cover just because it is transparent, you have to fill it with the background color (or background image) if you use DrawRec().
But I agree with @Erel, use B4XCanvas.
B4XCanvas.ClearRect (B4XCanvas.TargetRect)
Fx.Colors.Transparent doesn't cover just because it is transparent, you have to fill it with the background color (or background image) if you use DrawRec().
But I agree with @Erel, use B4XCanvas.
B4XCanvas.ClearRect (B4XCanvas.TargetRect)
Not something I thought about, but you're absolutely right, that'll be the solution! Thanks Klaus.
Solution:
Sub Process_Globals
Dim cnv As B4XCanvas
Dim Pane1 As Pane
Dim rect As B4XRect
Dim IMG As ImageView
End Sub
--
Sub DrawText
rect.Initialize(0, 0, Pane1.Width, Pane1.Height)
cnv.DrawText(New, BMP.Width/2, BMP.Height - 15dip, fx.LoadFont(File.DirAssets, "ITC_Souvenir_LT_Light.ttf", 48), xui.Color_Black, "CENTER")
IMG.SetImage(BMP.Snapshot2(fx.Colors.Transparent))
cnv.ClearRect(rect)
End Sub
I used ClearRect at the end because I didn't care to see the Canvas' text, I only wanted the stretched result which is set to the ImageView.
Not sure if Snapshot2 is needed here, but used it just in case to allow me to set the background to transparent.
Is there any reason why the author of B4XCanvas just couldn't bring it to themselves to include the "DrawPoint" method? Lots of other stuff is there, but I need to draw individual colored points unless I can figure something else out.