Android Question How do I get ABExtDrawing drawBitmap4 to only draw what is inside the source coordinates

Discussion in 'Android Questions' started by NeoTechni, Sep 10, 2018.

  1. NeoTechni

    NeoTechni Well-Known Member Licensed User

    When I use ABExtDrawing drawBitmap4, it draws the entire source image, instead of what's inside the source coordinates. I've been using a clip path to stop it from drawing the rest, but the larger the image is, the slower this method is. What is the proper way to draw an image as a polygon?

    Code:
    'SRC and DEST are an array of X-then-Y coordinates in the same direction (ie: clockwise)
    Sub DrawBMPpoly(BG As Canvas, BMP As Bitmap, SRC() As Float, DEST() As Float, Alpha As Int, NeedsClipPath As Boolean)
       
    Dim temp As Int, P As Path
       
    If SRC.Length = DEST.Length Then
           ExDraw.save2(BG, ExDraw.MATRIX_SAVE_FLAG)
           mPaint.Initialize
           mPaint.SetAlpha(Alpha)
           mMatrix.setPolyToPoly(SRC, 
    0, DEST, 0, DEST.Length *0.5)
           
    If NeedsClipPath Then
               P.Initialize(DEST(
    0),DEST(1))
               
    For temp = 2 To DEST.Length -1 Step 2
                   P.LineTo(DEST(temp),DEST(temp+
    1))
               
    Next
               BG.ClipPath(P)
           
    End If
           ExDraw.drawBitmap4(BG, BMP,  mMatrix, mPaint)
           ExDraw.restore(BG) 
    'before Activity.Invalidate
           If NeedsClipPath Then BG.RemoveClip
       
    End If
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Johan Hormaza likes this.
  3. NeoTechni

    NeoTechni Well-Known Member Licensed User

    I've actually been looking for that too. But it wouldn't apply in this scenario. I use DrawPoly mainly to fake 3D effects, like drawing a square texture as a parallelogram to make it seem like it's falling and such. But DrawPoly wants to draw the entire texture (which is huge) instead of just the part in the source coordinates... The drawing of the entire texture is what's slowing it down
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    In many cases you can improve the drawing performance by scaling down the canvas. Most devices scale is 2+ so the canvas size can be very large. The visual difference can be minimal.
     
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