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

Discussion in 'Android Questions' started by W. Graf, Jul 6, 2018.

  1. W. Graf

    W. Graf Member Licensed 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):

    Code:
    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, False12dip)
    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
     

    Attached Files:

  2. klaus

    klaus Expert Licensed 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.
     

    Attached Files:

    W. Graf likes this.
  3. W. Graf

    W. Graf Member Licensed 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
     
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