Android Question DrawPath() problem with Clipping? [SOLVED]

W. Graf

Member
Licensed User
Longtime User
Hi!

I'm having a question about ImageView, Canvas and DrawPath().

I want to draw multiple lines with DrawPath with this Code (see also attachment for a demo):

B4X:
Dim canvas1 As Canvas
canvas1.Initialize(ImageView1)

Dim PolygonPath As Path
PolygonPath.Initialize (64,154)
PolygonPath.LineTo (113,234)
PolygonPath.LineTo (193,114)
PolygonPath.LineTo (203,80)
PolygonPath.LineTo (293,54)
PolygonPath.LineTo (423,24)

canvas1.ClipPath(PolygonPath)
canvas1.DrawPath(PolygonPath,Colors.Cyan, False, 12dip)
canvas1.RemoveClip

Problem 1: there is often something like a "gap" in the line. If I remove a few points in the middle, then the gap sometimes disappears ... but this is no solution, because I need the points ;-)
Problem 2: the line on the end (on the right) is conical? Why is it not "normal" (angular)?

After many hours of investigation, I found the reason for it: ClipPath() and RemoveClip().
My first I thought: "Ok, I remove the lines and everything is working fine". And it really worked fine!

Do you know some reason, why I should use these lines?
I found the code above many months ago. Somebody posted it in a thread in this forum for a demo. Since I found this thread, I used it as template. But I never knew, why I have to use the clipper?

Do you think, it is bad, not to use the clipping-functions?

Thank you!!
BR Wolfgang
 

Attachments

  • DrawPathGap.zip
    9.2 KB · Views: 306

klaus

Expert
Licensed User
Longtime User
What exactly do you want to achieve?
Clipping is used if you want to limit the surface of the drawing.

Your PolygonPath is not a polygon, its a polyline, its not closed.
To get a polygon you need to add at the and a LineTo to the first point!

In your case, if you want to draw the polyline you must not use ClipPath and RemovePath!

Attached your modified project showing the differences.
 

Attachments

  • DrawPathGap1.zip
    9.3 KB · Views: 376
Upvote 0

W. Graf

Member
Licensed User
Longtime User
Hi Klaus,

thanks a lot. Great demo!!!

Polygon: you are right, it is a polyline (-> copy&paste-error).

Ok, it's good to know about the B4A-canvas-limitation. I have no problem about this - I only want to know it ;-)

Up to now, I totally misunderstood the Clipping-functions. But because of your demo, I understand what it is now.
Many many thanks for your time and work!!

Have a great weekend!
BR Wolfgang
 
Upvote 0
Top