Android Question [B4X] Drawing lines with BitmapCreator

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Private Sub line(BC As BitmapCreator, x1 As Int, y1 As Int, x2 As Int, y2 As Int, Color As Int)
    Dim Dx,Dy,Diff As Int
    Dim x,y As Float
   
    Dx = x2 - x1
    Dy = y2 - y1
    Diff=Max(Abs(Dx),Abs(Dy))
    For D=0 To Diff 
        x= x1 + Dx*D/Diff
        y = y1 + Dy*D/Diff
        If (x>=0 And x<BC.mWidth) And (y>=0 And y<BC.mHeight) Then BC.SetColor(x,y,Color)
    Next
End Sub

If you need to have one often 1dip each point you have to "enlarge" to 1dip.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Hello,

how can i draw a line with my finger or mouse on a bitmap with the BitmapCreator?
Like on Paint.

Greetings
With this trace the line.
To do the finger tracing you must have a view, even B4XView. and with the Touch event having the x, y coordinates
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
BitmapCreator almost doesn't include any drawing methods. BitmapCreator doesn't replace B4XCanvas / Canvas. They are expected to be used together.
The exact details depend on the problem you are trying to solve.

For a drawing app you should probably use B4XCanvas as the main drawing target and use BitmapCreator if you need to apply all kinds of lower level effects.
 
Upvote 0
Top