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

NeoTechni

Well-Known Member
Licensed User
Longtime 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?

B4X:
'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
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use BitmapCreatorEffects draw through mask feature:

SS-2018-09-11_08.41.59.png


https://www.b4x.com/android/forum/threads/b4x-bitmapcreator-effects.93608/#content

I don't think that it will be faster than clipping the path. The main advantage is that you can easily create complex shapes.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0
Top