Android Question draw q text on canvas

zoubair chaachouh

Member
Licensed User
Hello everybody,

I am a new on B4A, and i’m developing an APP whish show on the map some marker based in canvas.
My question is that i need to draw a text description on the canvas but is not working. After several time, I can show the text but not all the longitude just a part of the text.

This is my code :
B4X:
Sub CreateBitmap(text As String) As B4XBitmap
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    Dim Img01 As Bitmap =SetBitmapDensity(LoadBitmap(File.DirAssets,"car.png"))
    Dim rect01 As B4XRect
    p.SetLayoutAnimated(0, 0, 0, 50dip, 30dip)
    
    Dim c1 As B4XCanvas
    c1.Initialize(p)
    rect01.Initialize(50dip,0dip,50dip,40dip)
    c1.DrawRect(rect01, xui.Color_Transparent, True,3)
    c1.DrawBitmap(Img01,c1.TargetRect) ' nuevo
    c1.DrawText(text, c1.TargetRect.CenterX, c1.TargetRect.CenterY +2dip, xui.CreateDefaultBoldFont(15), xui.Color_Red, "LEFT")
    c1.Invalidate
    Return c1.CreateBitmap
End Sub

Thanks you for your helo
 

klaus

Expert
Licensed User
Longtime User
This looks strange to me:
p.SetLayoutAnimated(0, 0, 0, 50dip, 30dip)
You declare a panel with these properties:
Left = 0, Top = 0, Width = 50dip, Height = 30dip
Then you define a rectangle
rect01.Initialize(50dip,0dip,50dip,40dip)
with thes properties:
Left = 50 dip, which is outsodes the panel!
Top = 0, OK
Right = 50dip, which means that the width = 0 !?
Bottom = 40dip, which is higher than the panel height.
Therefore, c1.DrawRect(rect01, xui.Color_Transparent, True,3) does nothing.
 
Upvote 0

zoubair chaachouh

Member
Licensed User
This looks strange to me:
p.SetLayoutAnimated(0, 0, 0, 50dip, 30dip)
You declare a panel with these properties:
Left = 0, Top = 0, Width = 50dip, Height = 30dip
Then you define a rectangle
rect01.Initialize(50dip,0dip,50dip,40dip)
with thes properties:
Left = 50 dip, which is outsodes the panel!
Top = 0, OK
Right = 50dip, which means that the width = 0 !?
Bottom = 40dip, which is higher than the panel height.
Therefore, c1.DrawRect(rect01, xui.Color_Transparent, True,3) does nothing.

thanks you for you replay

I have tried using the same dimension, but the result is still the same. What I need is to write a long text description on the canvas keeping the image original dimension
 
Upvote 0
Top