B4A Library ABExtDrawing 1.0

victormedranop

Well-Known Member
Licensed User
Longtime User
I'm trying to rotate an image but no luck.

B4X:
Sub [B]Process_Globals[/B]
Dim ExDraw As ABExtDrawing
End Sub
Sub [B]Globals[/B]
Dim MyCanvas As Canvas
Dim Panel1 As Panel
End Sub
Sub [B]Activity_Create[/B](FirstTime As Boolean)
Activity.LoadLayout("1")
Panel1.Initialize("Panel1")
Panel1.Width = 20dip
Panel1.Height = 20dip
Dim m As ABMatrix
m.Initialize
m.postRotate(45)
m.postTranslate(10dip,10dip)
Dim b As Bitmap
Dim pnt As ABPaint
MyCanvas.Initialize(Panel1)
b.Initialize(File.DirAssets,"1488957559_swipe_left.png")
ExDraw.drawBitmap4(MyCanvas,b,m,pnt)
End Sub
[\code]
 

swChef

Active Member
Licensed User
Longtime User

I just took a look at this work, and made a few changes. This looks good on higher and lower density devices I have.

B4X:
Sub InitDrawingTools()
...
    ScalePaint.SetAntiAlias(True)
    ScalePaint.SetDither(True) ' added
    ScalePaint.SetLinearText(True) ' added
...
End Sub

Sub drawScale(Canv As Canvas)
    ExDraw.drawOval(Canv, scaleRect, ScalePaint)

    ExDraw.save2(Canv, ExDraw.MATRIX_SAVE_FLAG)

    Dim fMag As Float = 25
    Dim fOTS As Float = ScalePaint.GetTextSize
    Dim fOSW As Float =    ScalePaint.GetStrokeWidth
    ScalePaint.SetTextSize(fMag*fOTS)
    ScalePaint.SetStrokeWidth(fOSW*fMag)
    ExDraw.scale(Canv, 1/fMag, 1/fMag)
   
    Dim i As Int
    Dim y1 As Float
    Dim y2 As Float
    Dim y3 As Float
    Dim value As Int
    Dim valueString As String
    For i = 0 To totalNicks
        y1 = scaleRect.top
        If (i Mod 5 = 0) Then
            y2 = y1 - 0.025 ' for the 5 degree nicks
        Else
            y2 = y1 - 0.018
        End If
        y3 = y1 - 0.020 - 0.015
       
        value = nickToDegree(i)
        If (value >= minDegrees And value <= maxDegrees) Then
            ExDraw.drawLine(Canv, 0.5*fMag, fMag*y1, 0.5*fMag, fMag*y2, ScalePaint)
           
            If (i Mod 5 = 0) Then   
                valueString = value
                ExDraw.drawText(Canv, valueString, 0.5*fMag,fMag*y3, ScalePaint)
            End If
        End If
       
        ExDraw.rotate2(Canv, degreesPerNick, 0.5*fMag,fMag* 0.5)
    Next

    ScalePaint.SetStrokeWidth(fOSW)
    ScalePaint.SetTextSize(fOTS)
    ExDraw.restore(Canv)
End Sub

Sub nickToDegree(Nick As Int) As Int
    Dim rawDegree As Int
    If (Nick < totalNicks / 2) Then
        rawDegree = Nick*2
    Else
         rawDegree = (Nick - totalNicks) * 2
    End If
   
    Dim shiftedDegree As Int
   
    shiftedDegree = rawDegree + centerDegree
    Return shiftedDegree
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…