Android Question Graphic Lib for B4A Beginner

artsoft

Active Member
Licensed User
Longtime User
Hi all!

I am looking for a graphic library in order to have the possibility to create flickerfree graphics (lines, (filled) rectangles, circles etc.). It must be possible to create these graphical elements while touching the activity with my finger. While moving the finger the graphic should be changed a little bit, but flickerfree (double buffer?).

Is there already such a library?
Thx in advance.

Regards
ARTsoft
 

artsoft

Active Member
Licensed User
Longtime User
Thx for the quick response!
Perfect!

Is there any library which capsulates all graphical commands?
Or must i use the B4A commands collection for the canvas?

Best regards
ARTsoft
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Thanks a lot. I will try this lib.

At this moment i am playing with the canvas of a panel.

Perhaps you can help me: How to invalidate or clean a canvas.

Status:

I have 1 activity with 1 panel (panel size = activity size)
I get the canvas from this panel.
I draw a line to this canvas at the y position.
I increase the y pos by 10.
I draw a line again. But before i want to clear the canvas.

So the app should show always only 1 line moving to the bottom of the screen.

Background color of the panel is green - RGB(0.255.0)
Line color is red - RGB (255,0,0)

i use "DoEvents" in the loop to can react on click events in order to can terminate the app with a click.

But i see only a red background built by drawing only red lines.

Perhaps you can help or anybody here.

Thx again in advance.

Regards
ARTsoft


B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

    Dim i As Int
    Dim y As Int

    Activity.LoadLayout("main")

    If (FirstTime = True) Then
  
        cv.Initialize(Panel1)
  
    End If

    y = 0

    Do While (y < Activity.Height)
  
        cv.DrawLine(0, y, Activity.Width, y, Colors.RGB(255,0,0), 10)

        y = y + 10
  
        If (y >= Activity.Height) Then
  
            y = 0
  
        End If
      
        For i = 1 To 100
            DoEvents
        Next

        Panel1.Invalidate
  
    Loop

End Sub
 
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Update:

No i have a red line moving to the bottom ...

But the Panel background should be green. Now it is black .... Why?!

B4X:
Sub Activity_Create(FirstTime As Boolean)

    Dim i As Int
    Dim y As Int
    Dim areaRect As Rect

    Activity.LoadLayout("main")

    ' ------------------------------------------------------------------------------

    If (FirstTime = True) Then
        cv.Initialize(Panel1)
        areaRect.Initialize(0,0,Panel1.Width, Panel1.Height)
    End If

    ' ------------------------------------------------------------------------------

    y = 0

    Do While (y < Panel1.Height)
   
        cv.drawRect(areaRect, Colors.Transparent, True, 0)
        cv.DrawLine(0, y, Panel1.Width, y, Colors.RGB(255,0,0), 10)

        y = y + 10
   
        If (y >= Panel1.Height) Then
            y = 0
        End If

        Panel1.Invalidate

        DoEvents

    Loop

End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
You could use a routine like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    Panel1.Color = Colors.RGB(0, 255,0)

    cv.Initialize(Panel1)
    y = -10
    Do While (y < Activity.Height)
        cv.DrawLine(0, y, Activity.Width, y, Colors.RGB(0, 255,0), 10)
        y = y + 10
        cv.DrawLine(0, y, Activity.Width, y, Colors.RGB(255,0,0), 10)
        If (y >= Activity.Height) Then
            y = 0
        End If

        DoEvents
    
        Panel1.Invalidate
    Loop
End Sub
To erase the previous line you could draw it again with the panel background color.

What is this supposed to do?
B4X:
For i = 1 To 100
    DoEvents
Next
If you want to control the speed you should use a Timer.
 
Upvote 0
Top