Android Question Graphic Lib for B4A Beginner

Discussion in 'Android Questions' started by artsoft, May 4, 2015.

  1. artsoft

    artsoft Member Licensed 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The standard canvas creates flicker free graphics.
     
  3. artsoft

    artsoft Member Licensed 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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. artsoft

    artsoft Member Licensed 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


    Code:
    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 = TrueThen
      
            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: May 4, 2015
  6. artsoft

    artsoft Member Licensed User

    Update:

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

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

    Code:
    Sub Activity_Create(FirstTime As Boolean)

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

        
    Activity.LoadLayout("main")

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

        
    If (FirstTime = TrueThen
            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, True0)
            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
     
  7. DonManfred

    DonManfred Expert Licensed User

    Then paint a green background first. See the documentation of the canvas object.
    Especially DrawRect. Set the filled parameter to true
     
  8. klaus

    klaus Expert Licensed User

    You could use a routine like this:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    Activity.LoadLayout("main")
        Panel1.Color = 
    Colors.RGB(0255,0)

        cv.Initialize(Panel1)
        y = -
    10
        
    Do While (y < Activity.Height)
            cv.DrawLine(
    0, y, Activity.Width, y, Colors.RGB(0255,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?
    Code:
    For i = 1 To 100
        
    DoEvents
    Next
    If you want to control the speed you should use a Timer.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    The first step is to remove the DoEvents call and use a Timer as Klaus wrote.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice